求助!!

P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布

@[Wangyuqi2010](/user/1016748) `cmp` 的返回值类型是 `bool`,返回值只会是 $0$ 或 $1$。
by zhangbo1000 @ 2024-04-04 08:08:29


你 $cmp$ 里不能只写一部分,要把 $a>b$ 的情况也写了 ```cpp int cmp(int a,int b){ if(a==0&&b==0) return 3; if(a==0&&b==1) return 1; if(a==0&&b==2) return 2; if(a==0&&b==3) return 2; if(a==0&&b==4) return 1; if(a==1&&b==0) return 2; if(a==1&&b==1) return 3; if(a==1&&b==2) return 1; if(a==1&&b==3) return 2; if(a==1&&b==4) return 1; if(a==2&&b==0) return 1; if(a==2&&b==1) return 2; if(a==2&&b==2) return 3; if(a==2&&b==3) return 1; if(a==2&&b==4) return 2; if(a==3&&b==0) return 1; if(a==3&&b==1) return 1; if(a==3&&b==2) return 2; if(a==3&&b==3) return 3; if(a==3&&b==4) return 2; if(a==4&&b==0) return 2; if(a==4&&b==1) return 2; if(a==4&&b==2) return 1; if(a==4&&b==3) return 1; if(a==4&&b==4) return 3; } ``` 或者你也可以打个表 ```cpp int check[6][6] = { {3, 1, 2, 2, 1}, {2, 3, 1, 2, 1}, {1, 2, 3, 1, 2}, {1, 1, 2, 3, 2}, {2, 2, 1, 1, 3} }; int cmp(int a,int b){ return check[a][b]; } ```
by Agnehc @ 2024-04-04 08:13:51


然后你这一段其实就没啥用了 ```cpp if(cmp(x,y)==0) { int k=cmp(y,x); // cout<<i<<' '<<x<<' '<<y<<' '<<k<<'\n'; if(k==1){ aa++; }if(k==2){ bb++; }else ; continue; } ```
by Agnehc @ 2024-04-04 08:15:07


谢谢大佬 @[Agnehc](/user/1002848)
by Wangyuqi2010 @ 2024-04-04 13:51:53


```cpp #include<bits/stdc++.h> using namespace std; long long a[212],b[212],n,na,nb,ansa,ansb; int t[5][5]= { 0,0,1,1,0, 1,0,0,1,0, 0,1,0,0,1, 0,0,1,0,1, 1,1,0,0,0 }; int main() { cin>>n>>na>>nb; for(int i=0;i<na;i++)cin>>a[i]; for(int i=0;i<nb;i++)cin>>b[i]; for(int i=0;i<n;i++) { ansa+=t[a[i%na]][b[i%nb]]; ansb+=t[b[i%nb]][a[i%na]]; } cout<<ansa<<" "<<ansb; } ``` 可以这样打表
by 52hertz_yh @ 2024-04-07 16:26:54


|