forked from volzkzg/sgu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
153.cpp
61 lines (58 loc) · 1.17 KB
/
153.cpp
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
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <algorithm>
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define rrep(i,j,k) for (int i=j;i>=k;--i)
using namespace std;
int T,n,m,S[10],cirLen;
bool status[1001];//use false to mark N-Positions,true to mark P-Positions
bool check(int u,int w,int v)
{
rep(i,0,w-1)
if (status[u+i]!=status[v+i]) return false;
return true;
}
void theIniter()
{
cin >> n >> m;S[0] = 1;
rep(i,1,m) cin >> S[i];
status[0] = false;
rep(i,1,1000)
{
bool che = true;
rep(j,0,m)
{
if (i-S[j]<0) continue;
if (status[i-S[j]]) che = false;
}
status[i] = che;
}
rep(len,1,300)
{
bool che = true;
rep(t,1,(1000/len)-1)
if (!check(0,len,len*t)) {che = false;break;}
if (che) {cirLen = len;break;}
}
}
void thePrinter()
{
if (status[n%cirLen])
cout << "SECOND PLAYER MUST WIN" << endl;
else
cout << "FIRST PLAYER MUST WIN" << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin >> T;
while (T--)
{
theIniter();
thePrinter();
}
}