3 条题解

  • 6
    @ 2022-11-11 11:54:07

    这道题我的思路是将小a和小b的每一种出拳结果都枚举到一个二维数组中(以小a为基准),就像题目中的表格,其每一种出拳手势正好作为查找的索引,具体如下:

    char ans_map[5][5] = {{'s' , 'l' , 'w' , 'w' , 'l'} , 
                          {'w' , 's' , 'l' , 'w' , 'l'} , 
                          {'l' , 'w' , 's' , 'l' , 'w'} , 
                          {'l' , 'l' , 'w' , 's' , 'w'} , 
                          {'w' , 'w' , 'l' , 'l' , 's'}};
    

    其中:s代表平局,l代表输,w代表赢

    主要代码如下: Arule代表小a出拳周期 Brule代表小b出拳周期 av代表小a出拳周期索引 bv代表小b出拳周期索引 ascore代表小a分数 bscore代表小b分数 times代表出拳次数

    void winGame(int a , int b)
    {
        if (ans_map[a][b] == 'w')
        {
            ascore++;
        }
        else if (ans_map[a][b] == 'l')
        {
            bscore++;
        }
    }
    
    while (times < n)
        {
            times++;
            winGame(Arule[av] , Brule[bv]);
            av++;
            av %= na;
            bv++;
            bv %= nb;
        }
    
  • 5
    @ 2022-12-19 13:37:02
    #include<iostream>
    #include<cstdio>
    using namespace std;
    const int Maxn=210;
    inline void read(int &x){
    	int f=1;
    	char ch=getchar();
    	while(ch<'0'||ch>'9'){
    		if(ch=='-') x=-x;
    		ch=getchar();
    	}
    	while(ch>='0'&&ch<='9'){
    		x=(x<<3)+(x<<1)+(ch&15);
    		ch=getchar();
    	}
    	x*=f;
    }
    inline void write(int x){
    	if(x<0) putchar('-'),x=-x;
    	if(x>9) write(x/10);
    	putchar(x%10+'0');
    }
    int n,n_a,n_b;
    int a[Maxn],b[Maxn];
    int win[10][10]={{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}};
    signed main(){
    	int res1=0,res2=0;
    	read(n);read(n_a);read(n_b);
    	for(int i=0;i<n_a;i++) read(a[i]);
    	for(int i=0;i<n_b;i++) read(b[i]);
    	for(int i=0;i<n;i++){
    		res1+=win[a[i%n_a]][b[i%n_b]];
    		res2+=win[b[i%n_b]][a[i%n_a]];
    	}
    	write(res1),putchar(' '),write(res2);
    	return 0;
    }
    
    • 2
      @ 2024-2-10 19:26:04

      模仿下@以前的码风,大家千万不要告诉他哦~(逃

      不过思路好像有了

      #include <bits/stdc++.h>
      #define ll long long
      #define Rep(x, a, b) for (int x = a; x <= b; x++)
      #define Dep(x, a, b) for (int x = a; x >= b; x--)
      using namespace std;
      int n, na, nb, a[205], b[205], cnt1, cnt2;
      int vs[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()
      {
          ios::sync_with_stdio(false);
          cin.tie(0);
          cout.tie(0);
          cin >> n >> na >> nb;
          Rep(i, 0, na - 1)
              cin >> a[i];
          Rep(i, 0, nb - 1)
              cin >> b[i];
          Rep(i, 0, n - 1)
          {
              cnt1 += vs[a[i % na]][b[i % nb]];
              cnt2 += vs[b[i % nb]][a[i % na]];
          }
          cout << cnt1 << " " << cnt2 << endl;
          return 0;
      }
      
      • 1

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

      信息

      ID
      1424
      时间
      1000ms
      内存
      256MiB
      难度
      3
      标签
      递交数
      78
      已通过
      45
      上传者