Test Question Algorithm Training The Big Bang Version Rock Paper Scissors

Resource limit
Time limit: 1.0s Memory limit: 128.0MB


Problem description
  Rock-paper-scissors is a common guessing game: Rock-paper-scissors, paper-scissors-paper, and rock-paper-scissors. If two punches are the same, there is no difference. In the 8th episode of the second season of The Big Bang Theory, an upgraded version of rock, paper, scissors appeared. The upgraded version of the game adds two new gestures based on the traditional rock-paper-scissors game:
  Spock: one of the protagonists of "Star Trek".
  Lizardman: The opposite character in "Star Trek."
  The relationship between the outcome of these five gestures is shown in Table 1, which lists the game results of A vs. B
Insert picture description here


Now, Little A and Little B try to play this upgraded version of the guessing game. It is known that their punches are periodic and regular, but the length of the period is not necessarily equal. For example: if Little A punches in a period of "rock-cloth-rock-scissors-Lizardman-Spook" with a length of 6, then his punch sequence is "rock-cloth-rock-scissors-Lizardman-Spok" -Rock-Cloth-Rock-Scissors-Lizardman-Spock-......", and if Little B punches in a period of 5 "scissors-rock-cloth-Spook-Lizardman", then he punches The sequence is "Scissors-Rock-Boot-Spock-Lizardman-Scissors-Rock-Boot-Spock-Lizardman-..." It is
  known that Little A and Little B have performed a total of N guesses. Each time the person who wins gets 1 point, the person who loses gets 0 points; both of them get 0 points in a tie. Now please count the scores of the two after the N times of guessing.
Input format    The
  first line contains three integers: N, NA, NB, which respectively represent the period length of a total of N times of guessing, small A's punch, and the period of small B's punch. The number is separated by a space.
  The second line contains NA integers, representing the law of small A's punching, and the third line contains NB integers, representing the law of Small B's punching. Among them, 0 means "scissors", 1 means "rock", 2 means "cloth", 3 means "lizard man", and 4 means "spock". The number is separated by a space.


Output format
  output one line, containing two integers, separated by a space, representing the scores of small A and small B respectively.
Sample input
10 5 6
0 1 2 3 4
0 3 4 2 1 0
Sample output
6 2


Sample input
9 5 5
0 1 2 3 4
1 0 3 2 4
Sample output
4 4


Data description
  For 100% data, 0 <N ≤ 200, 0 <NA ≤ 200, 0 <NB ≤ 200.


Idea analysis:

Insert picture description here

  • Write down the A score and the loss of A (ie B score)
  • Find out the similarities and differences
  • Find the differences in the same

For example: when A[X]-B[Y]=-3, in the case of A score: A[X]=0, that is, when A[X]-B[Y]=-3 is also satisfied, And A[X]=0, under these two conditions, it is A score.

Source program:

#include<iostream>
using namespace std;
#define maxsize 10000
int a[maxsize];
int b[maxsize];
void init(int NA, int NB)//输入数据
{
    
    
	for (int i = 0; i < NA; i++)
		cin >> a[i];
	for (int i = 0; i < NB; i++)
		cin >> b[i];
}
void grade(int N,int NA,int NB)//输出两人的分数
{
    
    
	int sum1=0, sum2=0;
	int x, y, item;
	for (int i = 0; i < N; i++)//此处是猜拳N次
	{
    
    
		x = i%NA;//利用求余即可获得对应的编号
		y = i%NB;
		item = a[x] - b[y];//两者相见,根据上图所示,把A得分的条件和失分的条件写清楚即可。
		if (item > 0)
		{
    
    
			if (item == 2 || (item == 1 && a[x] == 4) || (item == 3 && a[x] == 3))//此处为B得分的情况,
				sum2++;
			else
				sum1++;
		}
		if (item < 0)
		{
    
    
			if (item == -2 || (item == -3 && a[x] == 0) || (item == -1 && a[x]  == 3))//A得分
				sum1++;
			else
				sum2++;
		}
	}
	cout << sum1 << " " << sum2;
}
int main()
{
    
    
	int N, NA, NB;
	cin >> N >> NA >> NB;
	init(NA, NB);
	grade(N, NA, NB);
}

Evaluation record:

Insert picture description here

supplement:

This question N refers to the number of boxing guessing. At the beginning, I thought that N was the number of rounds of boxing guessing. Then I felt that it was similar to the problem in the previous learning queue, and a circular queue was used. Later, I found that the test was wrong, and read the question again and found that N is the number of times. Good guys are much simpler. Then I thought that it was boring, I wanted to make a more real guess, so I changed the title:

  • N is the number of rounds performed
  • The two punches are irregular, that is, time seeds are added to generate random numbers according to the system time

I will publish this revised topic recently, and those who are interested can take a look.

Guess you like

Origin blog.csdn.net/weixin_49243150/article/details/113244781