甲乙两人玩一个游戏: 一张卡片上有个数字,甲乙两人轮流操作, 若当前卡片上的数字为x, 每次操作可以把它变为x+1或2x, 且不能超过n (例如n=8,x=6,只能变为7而不能变为12), 每次甲首先在卡片上写1,规定写n的人获胜。给定n, 问甲是否有必胜策略?
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int t; long long n; bool dfs(long long n) { if(n==2) return 0; else if(n%2) return 1; else return dfs(n/4); } int main() { cin>>t; while(t--) { cin>>n; bool f=dfs(n); if(f) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
原文:http://www.cnblogs.com/linda-fcj/p/7206129.html