zoukankan      html  css  js  c++  java
  • CSU 2018年12月月赛 H(2220): Godsend

    Description

    Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?

    Input

    First line of input data contains single integer n (1 ≤ n ≤ 1000000) — length of the array.

    Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 1000000000).

    Output

    Output answer in single line.

    "First", if first player wins, and "Second" otherwise (without quotes).

    Sample Input

    4
    1 3 2 3

    Sample Output

    First

    题意:给你n个数,第一个人能删去一个连续的子串当且只当这个连续子串所有数之和为奇数,同理第二个人删的是和为偶数的子串,谁不能操作了谁输。考虑这个总串和为偶数的情况,因为为奇数的时候第一个人直接全删了。
       当总和为偶数的时候,如果所有的数都是偶数的话,第一个人就没有办法删了,所以第二个人赢,不然那第一个先删去一段子串,剩余的子串之和肯定为奇数。第二个人删去偶数,肯定不能全删了,剩余的肯定是奇数,
       那么第一个人必赢。综上,只有所有的数都是偶数的时候第二个人才赢,否则第一个人赢 。
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <math.h>
    #include <set>
    using namespace std;
    const int maxn=230;
    int n,x,temp;
    string s;
    int main()
    {
        cin>>n;
        bool flag=false;
        while(n--)
        {
            scanf("%d",&x);
            if(x%2)
                flag=true;
        }
        if(flag==false)
            cout<<"Second"<<endl;
        else
            cout<<"First"<<endl;
        return 0;
    }
    
    /**********************************************************************
        Problem: 2220
        User: therang
        Language: C++
        Result: AC
        Time:256 ms
        Memory:2020 kb
    **********************************************************************/
  • 相关阅读:
    Memcached通信协议
    quartz在集群环境下的最终解决方案
    在中间层 .NET 应用程序中通过授权管理器使用基于角色的安全
    微软MVC框架实战:开源的JS库Knockout
    EL表达式
    Hadoop安装配置
    Memcached安装
    Maven对不同的测试环境用不同的参数进行打包
    项目管理案例:赢与非输之别
    十年WEB技术发展历程
  • 原文地址:https://www.cnblogs.com/jkzr/p/10163640.html
Copyright © 2011-2022 走看看