﻿HDU 2094 产生冠军(拓扑排序||乱搞)-Ocrosoft

# 产生冠军

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14134    Accepted Submission(s): 6463

Problem Description

Input

Output

Sample Input
```
3
Alice Bob
Smith John
Alice Smith
5
a c
c d
d e
b e
a d
0

```

Sample Output
```
Yes
No

```

Solution

```#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <list>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <cctype>
#include <queue>
#include <set>
#include <map>
#include <climits>
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
string rd(string &s)
{
cin>>s;
return s;
}
int main()
{
int n;
string s;
while(cin>>n&&n)
{
map<string,int> mp;
for(int i=0;i<n;i++)
{
if(!mp.count(rd(s)))mp[s]=1;//如果没有出现过，那么标记为1
mp[rd(s)]=0;//输的人标记为0
}
int cnt=0;
for(map<string,int>::iterator it=mp.begin();it!=mp.end()&&cnt<=1;it++)
if(it->second==1)cnt++;
printf("%s\n",cnt==1?"Yes":"No");
}
return 0;
}
```

```#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <list>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <cctype>
#include <queue>
#include <set>
#include <map>
#include <climits>
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
int main()
{
int n;
string s;
while(cin>>n&&n)
{
set<string> st;
set<string> all;
for(int i=0; i<n; i++)
{
cin>>s;
all.insert(s);
cin>>s;
all.insert(s);
st.insert(s);
}
if(all.size()-st.size()==1)printf("Yes\n");
else printf("No\n");
}
return 0;
}
```

```#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <list>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <cctype>
#include <queue>
#include <set>
#include <map>
#include <climits>
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
int main()
{
int n;
string s;
while(cin>>n&&n)
{
int in[1001]={0},k=0;
map<string,int> mp;
for(int i=0;i<n;i++)
{
cin>>s;
if(!mp.count(s))mp[s]=k++;
cin>>s;
if(!mp.count(s))mp[s]=k++;
in[mp[s]]++;
}
int cnt=0;
for(int i=0;i<k&&cnt<=1;i++)if(!in[i])cnt++;
printf("%s\n",cnt==1?"Yes":"No");
}
return 0;
}
```