예제 #1
0
bool canWinNim(int n)
{
    if(n <= 3)
        return true;
    else if(canWinNim(n-1) && canWinNim(n-2) && canWinNim(n-3))
        /* no matter 1, 2, or 3 strones you remove, you always can't win */
        return false;
    return true;
}
예제 #2
0
파일: 292.c 프로젝트: zhang-wen-guang/CODES
int main()
{
    int n;

    while (EOF != scanf("%d", &n)) {
        if (true == canWinNim(n)) printf("can win\n");
        else printf("can not win\n");
    }
    return 0;
}
예제 #3
0
int main(int argc, char* argv[])
{
    int n = atoi(argv[1]);
    int can = canWinNim(n);

    if(can)
        printf("yes\n");
    else
        printf("no\n");
    return 0;
}
예제 #4
0
int main(){
	srand((unsigned)time(0));
	int stone_num = rand() % 1000;

	if (canWinNim(stone_num))
		printf("When the number of stones are %d, first win!", stone_num);
	else
		printf("When the number of stones are %d, second win!", stone_num);

	// getchar();
	return 0;
}
예제 #5
0
int main()
{
	if (canWinNim(5))
	{
		std::cout << "win" << std::endl;
	}
	else
	{
		std::cout << "lose" << std::endl;
	}
	return 0;
}
예제 #6
0
파일: 292.c 프로젝트: DerrickChi/LeetCode
int main() {
    assert(canWinNim(1) == true);
    assert(canWinNim(4) == false);
    assert(canWinNim(5) == true);
    assert(canWinNim(7) == true);
    assert(canWinNim(34) == true);
    assert(canWinNim(1348820612) == false);

    printf("all tests passed!\n");

    return 0;
}
예제 #7
0
void NimGame::TestClass()
{
	cout<<"First Win="<<canWinNim(7)<<endl;
}