• E Alice and Bob


    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
     

    It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).

    If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

    Input

    The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

    Output

    Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

    Examples
    input
    2
    2 3
    output
    Alice
    input
    2
    5 3
    output
    Alice
    input
    3
    5 6 7
    output
    Bob
    Note

    Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

    起初一眼以为是一道博弈问题,后来发现就是一个GCD();

    求出GCD();后即可做倍数。

    注意最后要-n

    附AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int gcd(int a, int b)
     5 {
     6     return (b>0)?gcd(b,a%b):a;  
     7 }
     8 
     9 int main()
    10 {
    11     int n, a[120], i;
    12         cin>>n;
    13         int Max = 1;
    14         for(i = 0; i < n; i++)
    15         {
    16             cin>>a[i];
    17             if(a[i] > Max)
    18                 Max = a[i];
    19         }
    20         int p = a[0];  
    21         for(i = 1; i < n; i++)
    22             p = gcd(p, a[i]);
    23         int ans = Max/p - n;
    24         printf(ans&1 ? "Alice\n" : "Bob\n");
    25     return 0;
    26 }
  • 相关阅读:
    将Tomcat配置到你的mac电脑上,命令行启动tomcat
    Java反射获取字节码以及判断类型
    mysql那些事
    Hibernate 一对一中的一些问题
    Java long类型和Long类型的那些事
    java中的多线程
    Struts2:java.lang.NoSuchFieldException: resourceEntries at java.lang.Class.getDeclaredField(Class.java:1901)
    生产者-消费者模式
    并行程序设计模式--Master-Worker模式
    Ibatis的类型处理器TypeHandler解析
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5908643.html
Copyright © 2020-2023  润新知