洛谷 P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布 题解 C/C++

思路如下

方法一:if else 直接模拟
方法二:初始化一个二维数组  输和平记为0,赢记为1  直接索引
//P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <sstream>
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
#define clr(x) memset(x,0,sizeof((x)))
const int maxn = 10000;
#define MAX(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c)))
#define _max(a,b) ((a) > (b) ? (a) : (b))
#define _min(a,b) ((a) < (b) ? (a) : (b))
#define _for(a,b,c) for(int a = b;a<c;a++)
int r1,r2;
int arr[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}
};
void func(int x,int y) {
    
    
	//方法一 借用二维数组
	r1+=arr[x][y];
	r2+=arr[y][x];

	//方法二  用if else
	// if(x==y)return;
	// if(x==0) {
    
    
	// 	if(y==2||y==3)r1++;
	// 	else r2++;
	// }
	// else if(x==1) {
    
    
	// 	if(y==3||y==0)r1++;
	// 	else r2++;
	// }
	// else if(x==2) {
    
    
	// 	if(y==4||y==1)r1++;
	// 	else r2++;
	// }
	// else if(x==3) {
    
    
	// 	if(y==4||y==2)r1++;
	// 	else r2++;
	// }
	// else if(x==4) {
    
    
	// 	if(y==0||y==1)r1++;
	// 	else r2++;
	// }
}
int main()
{
    
    
#ifdef LOCAL 
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	int n,na,nb;
	cin>>n>>na>>nb;
	int a[205],b[205];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	for(int i = 0;i<na;i++) {
    
    
		cin>>a[i];
	}
	for(int j = 0;j<nb;j++) {
    
    
		cin>>b[j];
	}
	for(int i = 0;i<n;i++) {
    
    
		func(a[i%na],b[i%nb]);
		// cout<<a[i%na]<<" "<<b[i%nb]<<endl;
	}
	cout<<r1<<" "<<r2;
    return 0;
}


猜你喜欢

转载自blog.csdn.net/Jason__Jie/article/details/114340537