zoukankan      html  css  js  c++  java
  • 【Atcoder Grand Contest 010】D

    D - Decrementing


    Time limit : 2sec / Memory limit : 256MB

    Score : 1000 points

    Problem Statement

    There are N integers written on a blackboard. The i-th integer is Ai, and the greatest common divisor of these integers is 1.

    Takahashi and Aoki will play a game using these integers. In this game, starting from Takahashi the two player alternately perform the following operation:

    • Select one integer on the blackboard that is not less than 2, and subtract 1 from the integer.
    • Then, divide all the integers on the black board by g, where g is the greatest common divisor of the integers written on the blackboard.

    The player who is left with only 1s on the blackboard and thus cannot perform the operation, loses the game. Assuming that both players play optimally, determine the winner of the game.

    Constraints

    • 1≦N≦105
    • 1≦Ai≦109
    • The greatest common divisor of the integers from A1 through AN is 1.

    Input

    The input is given from Standard Input in the following format:

    N
    A1 A2AN
    

    Output

    If Takahashi will win, print First. If Aoki will win, print Second.


    Sample Input 1

    Copy
    3
    3 6 7
    

    Sample Output 1

    Copy
    First
    

    Takahashi, the first player, can win as follows:

    • Takahashi subtracts 1 from 7. Then, the integers become: (1,2,2).
    • Aoki subtracts 1 from 2. Then, the integers become: (1,1,2).
    • Takahashi subtracts 1 from 2. Then, the integers become: (1,1,1).

    Sample Input 2

    Copy
    4
    1 2 4 8
    

    Sample Output 2

    Copy
    First
    

    Sample Input 3

    Copy
    5
    7 8 8 8 8
    

    Sample Output 3

    Second

    ==============

    题目大意:给定n个最大公约数为1的整数,两个人轮流进行操作,每次操作可以选一个大于1的数使其减1,然后所有的数再除以当前的最大公约数(如3 6 10对10操作后得到1 2 3),当其中一个人无法操作时,输掉比赛,求获胜的是先手还是后手。先手输出First,后手输出Second。

    解:见Child-Single(good);

    #include<cstdio>
    #include<cstring>
    const int N=1e5+12;
    int map[N];int n;
    int gcd(int a,int b) 
    {
        if(!b) return a;
        return gcd(b,a%b); 
    }
    int dfs(int x)
    {
        int tot=0,flag=1;
        for(int i=1;i<=n;i++)     
            if(map[i]%2)
            {
                map[i]--;
                break;
            }
        int gc=map[1];
        for(int i=2;i<=n;i++) gc=gcd(gc,map[i]);
        for(int i=1;i<=n;i++)
        {
            map[i]/=gc;
            if(map[i]%2==0) tot++;
            if(map[i]==1) flag=0;
        }
        if(tot%2) return !x;
        if(!flag||n-tot>1) return x;
        dfs(x^1);
        
    }
    int main()
    {    
        scanf("%d",&n);
        int sum=0;
        int sum_flag=0,flag1=1;
        for(int i=1;i<=n;i++) 
        {
            scanf("%d",&map[i]);
            if(map[i]==1) flag1=0;
            if(map[i]%2==0) sum++;
            else sum_flag++;
    //        printf("std:: %d %d %d
    ",sum,sum_flag,flag1);
        }
        if(sum%2==1) printf("First
    ");
        else
        {
            if(!flag1||sum_flag>=2) printf("Second
    ");
            else if(dfs(1)) printf("First
    ");
            else printf("Second
    ");
        }
        return 0;
    }
    View Code

     ==========

     
  • 相关阅读:
    [转]我是如何走进黑客世界的?
    Pycharm里面使用PIL库之后,为什么调用Image的方法不能弹出代码提示,怎样能让代码提示弹出?
    查看Windows系统里的进程已运行的时间
    pyinstaller将py文件转成exe格式
    谈谈关于Python里面小数点精度控制的问题
    python访问百度地图接口并返回信息
    解决RabbitMQ service is already present
    IntelliJ IDEA :Error:(1, 1) java: 非法字符: 'ufeff'
    Intellij IDEA调试功能总结
    Tomcat8 启动中提示 org.apache.catalina.webresources.Cache.getResource Unable to add the resource
  • 原文地址:https://www.cnblogs.com/12fs/p/7723393.html
Copyright © 2011-2022 走看看