View Code of Problem 20

#include<iostream>
#include<cmath>
using namespace std;
bool Is(int n) {
	for (int i = 0;pow(2, i) <= n; i++)
	{
		if (n == pow(2, i))return true;
	}
	return false;
}
int takeStone(int n) {
	for (int i = 1; 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.


Back to problem 20