#include<iostream> #include<cmath> using namespace std; bool Is(int n) {//位运算判断是否位2的幂次方 bool flag = 0; if ((n > 0) && (n & (n - 1)) == 0) flag = 1; return flag; } int takeStone(int n) { for (int i = 0; pow(2,i)<=n; i++) { if (Is(n - pow(2, i))) {//如果下一次可以被拿完 continue; } else { return n - pow(2, i); } } return -1;//下一次必拿完 } int main() { int n; while (cin >> n) { int court = 0; for (int i = 0; ; i++) { n = takeStone(n); court++; if (n == -1) { court++; break; } } if (court % 2 == 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } } } |
Double click to view unformatted code.