poj2912Rochambeau

题目链接:http://poj.org/problem?id=2912

食物链那题差不多,稍微复杂一点。

枚举裁判,然后其他人判断是否冲突。

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 const int maxn=520;
 5 const int maxe=2010;
 6 int f[maxn],r[maxn],a[maxe],b[maxe];
 7 char op[maxe];
 8 int n,m;
 9 void init()
10 {
11     for(int i=0;i<n;i++){
12         f[i]=i;
13         r[i]=0;
14     }
15 }
16 
17 int gf(int x)
18 {
19     if(x!=f[x])
20     {
21         int t=f[x];
22         f[x]=gf(t);
23         r[x]=(r[x]+r[t])%3;
24     }
25     return f[x];
26 }
27 
28 int main()
29 {
30     while(scanf("%d%d",&n,&m)!=EOF)
31     {
32         for(int i=0;i<m;i++)
33         {
34             scanf("%d%c%d",&a[i],&op[i],&b[i]);
35             if(op[i]=='=') op[i]=0;
36             if(op[i]=='>') op[i]=1;
37             if(op[i]=='<') op[i]=2;
38         }
39         int only=1,judge=-1,round=0;
40         for(int i=0;i<n;i++)
41         {
42             init();
43             int ok=1;
44             for(int j=0;j<m;j++)
45             {
46                 if(a[j]==i||b[j]==i) continue;
47                 int aa=a[j],bb=b[j],opp=op[j];
48                 int pa=gf(aa);
49                 int pb=gf(bb);
50                 if(pa==pb)
51                 {
52                     if(r[aa]!=(r[bb]-opp+3)%3)
53                         {
54                             ok=0;
55                             round=max(round,j+1);  //记录第几轮证明出不是裁判
56                             break;
57                         }
58                 }
59                 else {
60                 f[pb]=pa;
61                 r[pb]=(r[aa]+opp-r[bb]+3)%3;
62                 }
63             }
64             if(ok)
65             {
66                 if(judge==-1) judge=i;
67                 else  {only=0;break;}
68             }
69         }
70         if(judge==-1) puts("Impossible");
71         else if(only==0) puts("Can not determine");
72         else printf("Player %d can be determined to be the judge after %d lines\n",judge,round);
73 
74     }
75     return 0;
76 }

 

转载于:https://www.cnblogs.com/yijiull/p/6616130.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值