This box has n ball, a, b two people take the ball in turn from the box, everyone can see how many other people have taken, also can see how many in the box, and both are very smart, will not make the wrong judgment. We agree:
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)
Please program to determine if both sides do not judge the error, for a particular initial number of balls, a can win? When the program runs, the data is obtained from standard input in the following format:
First an integer n (n<100), which indicates that there are n integers next. Then there are n integers, one for each row (integer <10000), representing the initial number of balls. The program outputs n lines, which indicates the winning and losing situation of a (lost to 0, winning is 1). For example, user input: 4 1 2 10 18
The program should output: 0 1 1 0
Thinking Analysis: A first to take the ball, then assume that the box has n ball when a win, that is, when the turn a to take the number of balls in the box is 0. Then, when there are 1, 3, 7, 8 balls in the box, a will lose. Therefore, when there are N balls, A's winning and losing situation is the opposite of i-1,i-3,i-7,i-8.
Package Ccq.lanqiao;import java.util.*;p ublic class main{public static void Main (string[] args) {Boolean array[]=new boolean[10020];array[0]=true;for (int i=1;i<10020;i++) {array[i]= (i>=1&&!array[i-1]) | | (i>=3&&!array[i-3]) | | (i>=7&&!array[i-7]) | | (I>=8&&!array[i-8]);} Scanner s=new Scanner (system.in); int n=s.nextint (); int total=0,result=0; Vector<integer> temp=new vector<integer> (); S.nextline (); for (int i=0;i<n;i++) {total=s.nextint (); Result=array[total]?1:0;temp.add (result);} for (int i=0;i<temp.size (); i++) {System.out.println (Temp.elementat (i));}}}
Blue Bridge Cup take the ball game