这题主要难在怎么判断输赢
这里有两种方法:
1、如果我们画出关系图
1、如果我们画出关系图
可以看出每个都是两赢两输自己和自己平
所以我们就可以构造一个5个位的环,如果对方猜拳和自己不一样,对方是自己的前两个是赢,否则是输
我们就构造了这个顺序:刀0,石1,斯2,布3,人4
斯可以赢 石 和 刀
但题目和本构造顺序不一样所以要调整
for (读a顺序){
如果是 3,4,5 就调整
}
for (读b顺序){
如果是 3,4,5 就调整
}
for (n个回合){
if (a==b) 不操作
else if (b是a的前两位) a赢
else b赢
} 代码 #include <bits/stdc++.h>
using namespace std;
const int N=10004;
int toa[N],tob[N];
int n,a,b,wina,winb;
int main(int argc, char** argv) {
cin>>n>>a>>b;
for(int i=0;i<a;i++){
cin>>toa[i];
if(toa[i]==2) toa[i]=3;
else if(toa[i]==3) toa[i]=4;
else if(toa[i]==4) toa[i]=2;
}
for(int i=0;i<b;i++){
cin>>tob[i];
if(tob[i]==2) tob[i]=3;
else if(tob[i]==3) tob[i]=4;
else if(tob[i]==4) tob[i]=2;
}
for(int i=0,pta=0,ptb=0;i<n;i++,pta=(pta+1+a)%a,ptb=(ptb+1+b)%b){
int aa=toa[pta],bb=tob[ptb];
if(aa==bb) ;
else if((aa-1+5)%5==bb||(aa-2+5)%5==bb) wina++;
else winb++;
}
cout<<wina<<" "<<winb<<endl;
return 0;
} 2、我们可以按关系表构建输赢表 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
for (n回合){
a分数wina+=win[a出拳][b出拳];
b分数winb+=win[b出拳][a出拳];
} 代码
#include <bits/stdc++.h>
using namespace std;
const int N=10004;
int toa[N],tob[N];
int n,a,b,wina,winb;
const int win[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(int argc, char** argv) {
cin>>n>>a>>b;
for(int i=0;i<a;i++){
cin>>toa[i];
}
for(int i=0;i<b;i++){
cin>>tob[i];
}
for(int i=0,pta=0,ptb=0;i<n;i++,pta=(pta+1+a)%a,ptb=(ptb+1+b)%b){
int aa=toa[pta],bb=tob[ptb];
wina+=win[aa][bb];
winb+=win[bb][aa];
}
cout<<wina<<" "<<winb<<endl;
return 0;
} 
京公网安备 11010502036488号