Sha 1500-Alice and Bob (reasoning)

Source: Internet
Author: User

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 must win ******************/# include <cstdio> # include <cstring> # include <algorithm> 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; RET Urn 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.