Links: Https://www.nowcoder.com/acm/contest/118/D
Source: Niu Ke Net
Topic Link: Click to open the link
Time limit: C/s 1 sec, other languages 2 seconds
Space limitations: C/C + + 32768K, other languages 65536K
64bit IO Format:%lld
Title Description
1, 2, 3 in playing basketball, but the two dozen one is always unfair, so they decided to a one-on, another person on the edge of watching, who lost who and the end and the side of the person watching the exchange. Now give you a sequence of victors (each round of winning people) and ask this sequence to be incompatible. (First singled out, 3 watched below)
Input Description:
The first number is the number n (1<=n<=100), which represents the size of the input winner sequence, and the next n lines describe the winner sequence. Line I contains a positive integer a[i], (1<=a[i]<=3), representing A[i] win the game
Output Description:
Output Yes if the winner sequence is legal, otherwise no
Example 1
input
3
1
1
2
2
1
2
Output
YES
NO
Description
In the first example, 1 won 2, 3 instead of 2, 1 won 3, 2 instead of 3, 2 won the
second example, 1 won 2, 3 instead of 2, when 2 was obviously already on the field, so it was impossible for the victor
Analysis:
Water problem
#include <stdio.h>
struct book{
int win,x1,x2;
} S[105];
int main ()
{
int n,a;
while (~SCANF ("%d", &n))
{
int bj=0;
s[0].x1=1;///initial state
s[0].x2=2;
for (int i=1;i<=n;i++)
{
scanf ("%d", &a),/////Winner////////////
for the time we enter, so if the value of BJ changes, it does not need to be judged. Because the wrong sequence has been found
if (!BJ)
{
if (a==s[i-1].x1| | A==S[I-1].X2)///If the winner is the contestant stating that it is eligible for the winner
{
s[i].x1=a;///one of the next contestants is the winner of this round if
(s[i-1].x1+s[i-1].x2==3)// /Find another contestant in the next round
s[i].x2=3;
else if (s[i-1].x1+s[i-1].x2==5)
s[i].x2=1;
else if (s[i-1].x1+s[i-1].x2==4)
s[i].x2=2;
}
else
bj=1;
}
}
if (BJ)
printf ("no\n");
else
printf ("yes\n");
}
return 0;
}