标签:style http color os io for ar line
题目大意:给出一个环,每次从起点开始,可以选择一个权值非0的边移动,移动后减掉权值至少1点。不能移动的为失败。
解题思路:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 30;
int N, arr[maxn];
bool check (int k) {
int p = -1;
while (arr[++p] != k);
int q = N;
while (arr[--q] != k);
q = N - 1 - q;
return (p&1) || (q&1);
}
bool judge () {
for (int i = 0; i < N; i++) {
if (arr[i] == 0)
return check(0);
}
if (N&1)
return true;
for (int i = 0; i < N; i++) {
if (arr[i] == 1)
return check(1);
}
return false;
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d", &N);
for (int i = 0; i < N; i++)
scanf("%d", &arr[i]);
printf("%s\n", judge() ? "YES" : "NO");
}
return 0;
}
uva 1561 - Cycle Game(推理),布布扣,bubuko.com
标签:style http color os io for ar line
原文地址:http://blog.csdn.net/keshuai19940722/article/details/38447177