hdu 2094 产生冠军
题意:给定n组u关系。每组表示a战胜b。。问根据这些关系能否确定冠军。 思路:如果a战胜b就从a连一条指向b的边。那么能确定冠军的条件就变成了,有且只有一个入度为0的点。翻译过来就是,有一个人没有被任何人战胜过。且,这样的人只有一个。一开始想用map来搞。。但是比较麻烦。。其实用set比较好。。开两个set,一个存所有的人,一个存输过的人。出度为0的点只有一个等价为,有且只有一个人没有输过。也就是两个set的元素差个数为1.
/* ***********************************************
Author :111qqz
Created Time :2015年12月08日 星期二 21时11分20秒
File Name :code/hdu/2094.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N= 1E3+7;
7int n;
8set<string>all;
9set<string>loser;
10int main()
11{
12 #ifndef ONLINE_JUDGE
13 freopen("code/in.txt","r",stdin);
14 #endif
1 while (scanf("%d",&n)!=EOF)
2 {
3 all.clear();
4 loser.clear();
5 if (n==0) break;
6 for ( int i = 0 ; i < n ;i++)
7 {
8 string win,lose;
9 cin>>win>>lose;
10 all.insert(win);
11 all.insert(lose);
12 loser.insert(lose);
13 }
14 if (all.size()-loser.size()==1)
15 {
16 puts("Yes");
17 }
18 else
19 {
20 puts("No");
21 }
22 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}