Sha 1500-Alice and Bob (reasoning)

Source: Internet
Author: User

Sha 1500-Alice and Bob (reasoning)

Question connection: Ultraviolet A 1500-Alice and Bob

In another sequence on the blackboard, you can choose one number minus one for each operation, or merge two numbers. If one number is reduced to one, it is automatically eliminated and cannot be lost by the operator.

Solution: the conclusion is that the number greater than 1 can be regarded as an integer s. To eliminate their total number of operation steps, including reducing 1 and merging, c is the number of 1 in the column, if s> 2, if c or s is an odd number, it will win. Otherwise, it will lose. If s is less than or equal to 2, (s = 2 or s = 0) is used to determine whether c is a multiple of 3. If yes, it will be defeated. If no, it will win.
Proof: When s> 2, s and c are both even numbers and are mandatory.
S is an odd number and c is an even number: Perform the first-hand operation to reduce s by 1 and transfer it to the mandatory State. S is an even number, and c is an odd number: Perform the first-hand operation. If a value of 1 is subtracted from 1, c will reduce 1 and move it to the mandatory State.
S is an odd number, and c is an odd number: combines a number in 1 and s. Transfer to the mandatory status.
S is an even number, c is an even number: s minus 1, then s is an odd number c is an even number, must win state; c minus 1, then s is an even number c is an odd number, must win state; merge the numbers of 1 and non-1, and the odd numbers of s and c are mandatory;
When s = 0 or s = 2, when c % 3 = 0, it is a mandatory defeat.
When c % 3 = 1, a 1 minus 1, c % 3 = 0, is transferred to the mandatory State.
C % 3 = 2, for s = 0, merge two 1, it becomes s + 2, C-2, if s = 0, when s = 2, c % 3 = 0 will fail. For s = 2, if s is reduced by 1, s is changed to 1, therefore, the number of 1 is increased by 1, So c % 3 = 0.
When c % 3 = 0, if a value of 1 is reduced, the system is absolutely competitive.

/****************** C is the number of 1, and s is the total number of other non-1 steps, including merging. * S> 2, c wins if it is an odd number, and if it is an even number, s wins if it is an odd number. * s = 2 | s = 0, if c is not a multiple of 3, it will win ******************/# include
  
   
# Include
   
    
# Include using namespace std; int n, c, s, x; void init () {c = s = 0; scanf ("% d", & n ); for (int I = 0; I <n; I ++) {scanf ("% d", & x); if (x = 1) c ++; else if (x> 1) s + = (x + 1);} if (s) s --;} bool judge () {if (s> 2) return (c & 1) | (s & 1); if (s = 0) return c % 3; return c % 3;} int main () {int cas; scanf ("% d", & cas); for (int k = 1; k <= cas; k ++) {init (); printf ("Case # % d: % s \ n ", k, judge ()? "Alice": "Bob");} return 0 ;}
   
  

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.