-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircularGame.cpp
More file actions
88 lines (65 loc) · 1.45 KB
/
CircularGame.cpp
File metadata and controls
88 lines (65 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// problem: "https://www.hackerrank.com/contests/bfme-2/challenges/circular-card-game"
#include<iostream>
#include<vector>
using namespace std;
int comp(int x)
{
if(x==0)
return 1;
if(x==1)
return 0;
return -1;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int>V(n);
int i;
for(i=0;i!=n;i++)
cin>>V[i];
for(i=0;i!=n;i++)
{
if(V[i]==1)
{
V[i] = -1;
if(i==0)
V[n-1] = comp(V[n-1]);
else
V[i-1] = comp(V[i-1]);
if(i==n-1)
V[0] = comp(V[0]);
else
V[i+1] = comp(V[i+1]); // define
int j = i-1;
while(j>=0 && V[j]==1)
{
if(j==0)
{
V[0] = -1;
V[n-1] = comp(V[n-1]);
break;
}
V[j] = -1;
V[j-1] = comp(V[j-1]);
j--;
}
}
}
int c = 0;
for(i=0;i!=n;i++)
if(V[i] == 0)
c = 1;
if(n==2 && V[0]!=V[1])
c = 0;
if(c == 1)
cout<<"No\n";
else
cout<<"Yes\n";
}
return 0;
}