HDU-1811 Rank of Tetris
生活随笔
收集整理的這篇文章主要介紹了
HDU-1811 Rank of Tetris
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Rank of Tetris
Time Limit: 1000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11843????Accepted Submission(s): 3362
http://acm.hdu.edu.cn/showproblem.php?pid=1811
Problem Description 自從Lele開發了Rating系統,他的Tetris事業更是如虎添翼,不久他遍把這個游戲推向了全球。為了更好的符合那些愛好者的喜好,Lele又想了一個新點子:他將制作一個全球Tetris高手排行榜,定時更新,名堂要比福布斯富豪榜還響。關于如何排名,這個不用說都知道是根據Rating從高到低來排,如果兩個人具有相同的Rating,那就按這幾個人的RP從高到低來排。
終于,Lele要開始行動了,對N個人進行排名。為了方便起見,每個人都已經被編號,分別從0到N-1,并且編號越大,RP就越高。
同時Lele從狗仔隊里取得一些(M個)關于Rating的信息。這些信息可能有三種情況,分別是"A > B","A = B","A < B",分別表示A的Rating高于B,等于B,小于B。
現在Lele并不是讓你來幫他制作這個高手榜,他只是想知道,根據這些信息是否能夠確定出這個高手榜,是的話就輸出"OK"。否則就請你判斷出錯的原因,到底是因為信息不完全(輸出"UNCERTAIN"),還是因為這些信息中包含沖突(輸出"CONFLICT")。
注意,如果信息中同時包含沖突且信息不完全,就輸出"CONFLICT"。
?
Input 本題目包含多組測試,請處理到文件結束。每組測試第一行包含兩個整數N,M(0<=N<=10000,0<=M<=20000),分別表示要排名的人數以及得到的關系數。
接下來有M行,分別表示這些關系
?
Output 對于每組測試,在一行里按題目要求輸出?
Sample Input 3 3 0 > 1 1 < 2 0 > 2 4 4 1 = 2 1 > 3 2 > 0 0 > 1 3 3 1 > 0 1 > 2 2 < 1?
Sample Output OK CONFLICT UNCERTAIN 比起一般的拓撲排序,多了一個等于的條件。但是如果用并查集將等于的多項歸于一項就是裸的拓撲排序了 #include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <string> #include <vector> #include <set> #include <algorithm> using namespace std; #define M 20005 #define N 105 int l[M],r[M],head[M],aa[M],m,n,rudu[M]; char ch[M]; struct node {int to,next; }bian[M]; int find(int a) {while(a!=aa[a])a=aa[a];return a; } void inti() {memset(rudu,0,sizeof(rudu));memset(head,-1,sizeof(head));for(int i=0;i<=n;i++)aa[i]=i; } int top=0; void add(int a,int b) {bian[top].to=b;bian[top].next=head[a];head[a]=top++; } int main() {int A,B;while(cin>>n>>m){inti();int num=n;for(int i=0;i<m;i++){cin>>l[i]>>ch[i]>>r[i];if(ch[i]=='='){A=find(l[i]);B=find(r[i]);if(A!=B)aa[B]=A,num--;}}int flag=0;for(int i=0;i<m;i++){if(ch[i]=='=')continue;A=find(l[i]);B=find(r[i]);if(ch[i]=='>'){add(A,B);rudu[B]++;}if(ch[i]=='<'){add(B,A);rudu[A]++;}}queue<int> q;for(int i=0;i<n;i++)if(rudu[i]==0&&i==find(i))q.push(i);while(!q.empty()){if(q.size()>1)flag=1;num--;int t=q.front();q.pop();for(int i=head[t];i!=-1;i=bian[i].next)if(--rudu[bian[i].to]==0)q.push(bian[i].to);}if(num>0)cout<<"CONFLICT"<<endl;else if(flag)cout<<"UNCERTAIN"<<endl;else cout<<"OK"<<endl;}return 0; }
轉載于:https://www.cnblogs.com/SparkPhoneix/p/9413992.html
總結
以上是生活随笔為你收集整理的HDU-1811 Rank of Tetris的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: golang刷Leetcode系列 --
- 下一篇: Git区分文件名大小写