zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    3、Python文件操作工具 xlwt 工具
    2、Python文件操作工具 xlrd 工具
    1、关于python第三方工具操作xls和xlsx格式的excel文档选型的吐血经历
    设置python的默认编码方式为utf-8
    Python安装第三方库 xlrd 和 xlwt 。处理Excel表格
    I/O字符流
    I/O字节流
    读写锁实现线程安全缓存
    红黑树理解
    Task异常捕获
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5908643.html
Copyright © 2011-2022 走看看