uva 1561 - Cycle Game(推理)
2014-08-09 03:13
302 查看
题目链接:uva 1561 - Cycle Game
题目大意:给出一个环,每次从起点开始,可以选择一个权值非0的边移动,移动后减掉权值至少1点。不能移动的为失败。
解题思路:
1:有0的情况,如果有方向离权值为0的边的步数为奇数,则为必胜;否则必败;
2:无0的情况,奇数边必胜;
3:有1的情况,同0的判断一样;
4:无1的情况,只剩偶数边的情况,必败;
题目大意:给出一个环,每次从起点开始,可以选择一个权值非0的边移动,移动后减掉权值至少1点。不能移动的为失败。
解题思路:
1:有0的情况,如果有方向离权值为0的边的步数为奇数,则为必胜;否则必败;
2:无0的情况,奇数边必胜;
3:有1的情况,同0的判断一样;
4:无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(推理)
- uva 1445 - Cubist Artwork(推理)
- UVA 1315 - Crazy tea party(数论+推理)
- UVA - 1614 Hell on the Markets 贪心+推理
- UVALive - 3029 City Game 推理
- UVa 1614 Hell on the Markets (贪心+推理)
- UVA 10339 - Watching Watches(数论+推理)
- UVA 11246 - K-Multiple Free set(数论推理)
- UVALive - 2678 Subsequence 推理
- uva 11400 DP 需要推理
- UVa 10791 - Minimum Sum LCM (数论 推理)
- UVA 11024 - Circular Lock(数论+推理)
- UVA 1388 - Graveyard (推理,参考系)
- UVA 10771 - Barbarian tribes(推理)
- uva - UVA 1388 - Graveyard (数学推理)
- uva 11892 - ENimEN(推理)
- UVa 11892 ENimEn(博弈推理)
- UVA1418-WonderTeam(推理+贪心)
- UVA - 1611 Crane 推理 + 贪心
- UVA 1474(dp + 推理)