Acdream 1684 Nana sleepwalking Wonderland Series--inexplicable episode (GCD)

Source: Internet
Author: User
Tags greatest common divisor

Test instructions: At first there is a collection, there are n different numbers in the collection, then Alice (Nana) and Bob take turns to operate, each can choose two number of a, B, may wish to set a>b, but requires a-a is not in the collection, put a-B into the collection (the collection element number only increases). If it's someone's turn and can't do anything, the person loses the game. When Alice and Bob all follow the best strategy, Nana wins, who will win?

Thought: Minus to subtract, with greatest common divisor gcd similar. There is no optimal strategy for this problem, all are equal. The use of the game is not knowledge.

The last situation that cannot be manipulated must be {1g, 2g,3g......xg},3g means that 3*g,g represents greatest common divisor. Such a situation can not be manipulated, who loses. How many steps will it take to create such a situation? The largest element of the original sequence will not disappear from the set, so equal to XG, then the "dead situation" each element divided by G into {1,2,3.....x}, so the final situation has x elements, and the sequence is n elements, because each operation adds a number, so the work went x-n step, Odd steps for the initiator to win.

Summary, this problem needs to be required is GCD,BIG/GCD minus N, and then sentenced to parity results.

  

1 /*2 * This code was made by xcw07543 * problem:16844 * verdict:accepted5 * Submission date:2015-07-19 23:45:136 * time:0ms7 * MEMORY:1680KB8 */9#include <bits/stdc++.h>Ten using namespacestd; One Const intn=1050; A intA[n]; -   - intCalintN) the { -Sort (a,a+n); -     inttmp=a[0]; -      for(intI=1; i<=n; i++) +tmp=__GCD (Tmp,a[i]); -     returntmp; + } A intMainvoid) at { -     //freopen ("E://input.txt "," R ", stdin); -     intt, N; -Cin>>T; -      while(t--) -     { inscanf"%d",&n); -         intbig=0; to          for(intI=0; i<n; i++) +         { -scanf"%d",&a[i]); thebig=Max (big,a[i]); *         } $         intGcd=cal (n);//Greatest Common DivisorPanax Notoginseng         intans=big/gcd-N; -         if(ans&1) puts ("Win"); the         ElsePuts"lose"); +     } A     return 0; the}
AC Code

Acdream 1684 Nana sleepwalking Wonderland Series--inexplicable episode (GCD)

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.