HDU 2094 产生冠军

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2094

图论 拓扑排序 不过难点是输入的是字符 用STL map

View Code
 1 #include<iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<map>

 5 using namespace std;

 6 map<string,int>p;

 7 int o[2001][2001],key[2001];

 8 char str1[100],str2[100];

 9 int main()

10 {

11     int i,j,k,n,num,z;

12     while(scanf("%d%*c",&n)!=EOF&&n!=0)

13     {

14         z=0;

15      memset(o,0,sizeof(o));

16      memset(key,0,sizeof(key));

17      p.clear();

18      num=1;

19      for(i=1;i<=n;i++)

20      {

21          scanf("%s%s",str1,str2);

22          if(p[str1]==0)

23          {

24              p[str1]=num;

25              num++;

26          }

27          if(p[str2]==0)

28          {

29              p[str2]=num;

30              num++;

31          }

32          j=p[str1];

33          k=p[str2];

34          if(!o[j][k])

35          {

36              o[j][k]=1;

37              key[k]++;

38          }

39      }

40      for(i=1;i<=num-1;i++)

41      if(!key[i])

42      {

43          z++;

44      }

45      if(z==1)

46      printf("Yes\n");

47      else

48      printf("No\n");

49     }

50     return 0;

51 

52 }

你可能感兴趣的:(HDU)