Poj 1029

传送门

判断假硬币,前面好像有道类似的题(Poj 1013),这个题比之前那个多了一个可能有无法判断的情况

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cmath>
 4 using namespace std;
 5 
 6 char C;
 7 int N,K;//1000 100
 8 int P;
 9 int maxx;
10 bool flag;
11 int coin[1005];
12 int Left[500];
13 int Right[500];
14 
15 int main(){
16     cin>>N;
17     memset(coin,0,sizeof(coin));
18     cin>>K;
19     while(K--){
20         cin>>P;
21         for(int i=0;i<P;i++){
22             cin>>Left[i];
23         }
24         for(int i=0;i<P;i++){
25             cin>>Right[i];
26         }
27         cin>>C;
28         if(C=='='){
29             for(int i=0;i<P;i++){
30                 coin[Left[i]]=200;
31                 coin[Right[i]]=200;
32             }
33         }
34         else if(C=='<'){
35             for(int i=0;i<P;i++){
36                 if(coin[Left[i]]!=200){
37                     coin[Left[i]]--;
38                 }
39                 if(coin[Right[i]]!=200){
40                     coin[Right[i]]++;
41                 }
42             }
43         }
44         else if(C=='>'){
45             for(int i=0;i<P;i++){
46                 if(coin[Left[i]]!=200){
47                     coin[Left[i]]++;
48                 }
49                 if(coin[Right[i]]!=200){
50                     coin[Right[i]]--;
51                 }
52             }
53         }
54     }
55     maxx=0;
56     flag=true;
57     for(int i=1;i<=N;i++){
58         if(coin[i]!=200&&maxx==0&&fabs(coin[i])>=fabs(coin[maxx])){
59             maxx=i;
60         }
61         else if(coin[i]!=200&&fabs(coin[i])>fabs(coin[maxx])){
62             flag=true;
63             maxx=i;
64         }
65         else if(coin[i]!=200&&fabs(coin[i])==fabs(coin[maxx])){
66             flag=false;
67         }
68     }
69     if(flag){
70         cout<<maxx<<endl;
71     }
72     else{
73         cout<<0<<endl;
74     }
75 } 

 

posted @ 2017-07-21 11:32  水野玛琳  阅读(342)  评论(0编辑  收藏  举报