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.2.5 复制节点:
    1.创建元素节点:
    有多少漏洞都会重来:从ElasticSearch到MongoDB和Redis
    登陆密码显示与不显示的切换
    计算机网络基础 — Linux 路由器
    作为白手起家的企业家,必经阶段你经历了几个?
    竞争越来越大,创业公司怎么才能走的越来越远?
    城市竞争太大?这有农村创业七大项目,让你远离竞争
    短视频的改革带来的风暴,网红又该何去何从?
    照着官方文档学习react
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5908643.html
Copyright © 2011-2022 走看看