Life Big Bang version stone scissors cloth
(Rps.cpp/c/pas)
"Problem description"
Stone scissors cloth is a common scissors game: Stone wins scissors, scissors wins cloth, Bushe stone. If two people punch the same, then dead heat. In the 8th episode of the second quarter of the Big Bang, a new version of the rock-and-scissors-cloth game appeared. The upgraded version of the game is based on the traditional stone scissors cloth game, adding two new gestures:
Spock: One of the leading stars of Star Trek.
Lizard Man: The reverse role in Star Trek.
The outcome of these five gestures is shown in table one, and the table shows the results of a pair B game.
Table A stone scissors cloth upgrade version of the outcome relationship
b A to B results |
|
stone |
cloth |
lizard man |
|
scissors |
flat |
lose |
win |
win |
Span style= "font-family: italics;" > lose |
stone |
  |
flat |
output |
win |
Span style= "font-family: italics;" > lose |
fabric |
  |
|
flat |
" |
win |
lizard man |
  |
|
  |
flat |
win |
Spock |
|
|
|
|
Flat |
Now, small A and little B try to play this upgraded version of the scissors game. They are known to have a cyclical pattern, but the cycle length is not necessarily equal. For example: If small a punches with a 6-length cycle of "stone-cloth-stone-scissors-lizard Man-Spock", then his punch sequence is "stone-cloth-stone-scissors-lizard man-rock-stone-cloth-stone-scissors-lizard man-Spock-......", and if little B takes " Scissors-stone-cloth-lizard Man "The length of the 5-period punch, then his punch sequence is" scissors-stone-cloth-the lizard-man-scissors-stone-cloth-rock-lizard man-...... "
It is known that small A and small b are scissors for n times altogether. Each winning person has 1 points, loses 0 points, the draw two people both have to have 0 points. Now, please count the scores of the two people after the N-times scissors ended.
Input
The input file name is rps.in.
The first line contains three integers: N,NA,NB, representing the period length of a total of N times scissors, small a punch, and the period length of the small B punch. The number and number are separated by a space.
The second line contains Na integers, representing the law of small a punch, and the third line contains NB integers representing the law of the small B punch. Among them, 0 means "scissors", 1 means "stone", 2 means "cloth", 3 means "lizard Man", 4 means "rock". The number and number are separated by a space.
Output
The output file name is Rps.out.
Output a row, containing two integers, separated by a space, representing the score of small A and small B respectively.
"Input and output Example 1"
Rps.in |
Rps.out |
10 5 6 0 1 2) 3 4 0 3 4 2 1 0 |
6 2 |
"Input and output Example 2"
Rps.in |
Rps.out |
9 5 5 0 1 2) 3 4 1 0 3) 2 4 |
4 4 |
"Data description"
For 100% of data, 0 < n≤200,0 < na≤200, 0 < nb≤200.
In this way, directly simulate the results of each scissors ... Time complexity O (n), spatial complexity O (n)
However, in the examination room, the brain hole a bit of capital a least common multiple ... It's okay anyway AC on the line ...
Time Complexity O (LCM (NA,NB)) ...
Code:
1 Const2WinArray[0..4,0..4] ofboolean=3 ((false,false,true,true,false),4 (true,false,false,true,false),5 (false,true,false,false,true),6 (false,false,true,false,true),7 (True,true,false,false,false));8 9 varTenB:Array[0..40001] ofLongint; OneC:Array[0..40001,1..2] ofLongint; A N,na,nb,nc,ans1,ans2,i,now:longint; - - functiongcd (x,y:longint): Longint; the begin - ifXMoDy=0 - Thengcd:=y - ElseGCD:=GCD (y,xMoDy); + End; - + procedureRead_ready; A begin at readln (N,NA,NB); - fori:=1 toNa Do - read (a[i]); - fori:=1 tonb Do - read (b[i]); - ifNa>NB in Thennc:=gcd (NA,NB) - Elsenc:=gcd (Nb,na); toNc:=na*nbDivNC; + fori:=1 tonc Do - begin thea[i]:=a[(I-1)MoDna+1]; *b[i]:=b[(I-1)MoDnb+1]; $ End;Panax Notoginseng End; - the procedureChushihua; + begin AFillchar (A,sizeof (a),0); theFillchar (b,sizeof (b),0); +Fillchar (C,sizeof (c),0); -ans1:=0; ans2:=0; $ End; $ - procedureWork ; - begin thec[0,1]:=0; c[0,2]:=0; - fori:=1 tonc DoWuyi begin theC[i,1]:=c[i-1,1]; -C[i,2]:=c[i-1,2]; Wu ifWin[a[i],b[i]] ThenInc (C[i,1]); - ifWin[b[i],a[i]] ThenInc (C[i,2]); About End; $Ans1:= (nDivNC) *C[NC,1]; -Ans2:= (nDivNC) *C[NC,2]; -N:=nMoDNC; -Inc (Ans1,c[n,1]); AInc (Ans2,c[n,2]); +Writeln (ANS1,' ', ans2); the End; - $ begin the Chushihua; the Read_ready; the Work ; the End.
NOIP d1t1-life Big Bang version of stone scissors cloth