Blue Bridge Cup take the ball game

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.