FJNU Race _acdream1684 (game)

Source: Internet
Author: User
Tags greatest common divisor

Test instructions

Gives a set of n numbers;

And then each time you can go to two numbers a and B, the difference between the two (big-small) is not in the collection, and put a B into the array;

Who finally can not take the number to lose;

Ask the initiator to win or to lose;


Ideas:

First, all numbers of greatest common divisor g, and the maximum of all numbers m;

For example, greatest common divisor is 2, such as the original array is 2,6,8

Then the assembly may only appear 2,4,6,8;

Likewise if the greatest common divisor of the set is 3

Then the collection can only appear 3,6,9,12 ....

So the m/g is that this set can eventually have several numbers;

Minus the original n, is also can put in a few;

To judge the parity of the knowledge that the initiator is to win the loss;


#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int n = 1005;int N, Num[n];int gcd (int x, int y) {return y = = 0? x:gcd (y, x% y);} int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%d", &n), scanf ("%d", &num[0]); int g = num[0];int m = num[0 ];for (int i = 1; i < n; i++) {scanf ("%d", &num[i]), G = gcd (G,num[i]); m = max (M, Num[i]);} if (((m/g)-N)% 2) printf ("win\n"); elseprintf ("lose\n");}}


FJNU Race _acdream1684 (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.