There are n balls in this box, and A and B two take the ball from the box in turn.
Everyone can see how many other people have taken and how many are left in the box.
Both of them are very clever and don't make false judgments.
The number of balls that each person pulls out of the box must be: 1,3,7 or 8.
You cannot abstain from taking the ball on one side!
A take the ball first, then the two sides take the ball alternately, until the end is taken.
The one who is forced to get the last ball is the negative side (the loser)
Programming determines whether a can win for a given initial number of balls if both parties do not judge the error.
#include <iostream>using namespace Std;int f (int n) {if (n==0) return 1;//The following is the notation one, is Right/*if ((n>=1) &&f (n-1 ) ==0 return 1;if ((n>=3) &&f (n-3) ==0) return 1;if ((n>=7) &&f (n-7) ==0) return 1;if ((n>=8) & &f (n-8) ==0) return 1;*///The following is the notation two, wrong if (f (n-1) ==0&&n>=1) return 1;if (f (n-3) ==0&&n>=3) return 1;if (f (n-7) ==0&&n>=7) return 1;if (f (n-8) ==0&&n>=8) return 1;return 0; int main () {int i;for (i = 1; i <=; i++) {string s= (f (i) ==1)? " Can win ":" Can not win ";cout<<i<<": ' <<s<<endl; }return 0;}
The short-circuit characteristics of--c language logic operation in the ball-taking problem