标签:hdu2094
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8523 Accepted Submission(s): 4009
3 Alice Bob Smith John Alice Smith 5 a c c d d e b e a d 0
Yes No
STL版本 93ms:统计总人数和输掉的人数,若总-输==1则Yes,否则No。但是有个bug,比如A B, B C, D E, E F, F D。。
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main()
{
int n, count;
string a, b;
set<string> st, total;
while(scanf("%d", &n), n){
st.clear(); total.clear();
count = 0;
while(n--){
cin >> a >> b;
total.insert(a);
total.insert(b);
if(!st.count(b)){
++count; st.insert(b);
}
}
if(total.size() - st.size() == 1) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
拓扑排序版本 15ms:只需要保证入度为0的点只有一个即可,无上述bug。
#include <stdio.h>
#include <string.h>
char str[2002][22];
int inDegree[2002], id;
int find(char str1[])
{
for(int i = 0; i < id; ++i)
if(!strcmp(str1, str[i])) return i;
return -1;
}
void insert(char str1[])
{
if(find(str1) != -1) return;
strcpy(str[id++], str1);
}
int main()
{
int n, i, count;
char str1[22], str2[22];
while(scanf("%d", &n), n){
memset(inDegree, 0, sizeof(inDegree));
id = count = 0;
while(n--){
scanf("%s%s", str1, str2);
insert(str1); insert(str2);
++inDegree[find(str2)];
}
for(i = 0; i < id; ++i)
if(!inDegree[i]) ++count;
if(count == 1) printf("Yes\n");
else printf("No\n");
}
return 0;
}
HDU2094 产生冠军 【STL】,布布扣,bubuko.com
标签:hdu2094
原文地址:http://blog.csdn.net/chang_mu/article/details/38320687