【Codeforces Round #429 (Div. 2) B】 Godsend

Link:http://codeforces.com/contest/841/problem/B

Description

两个人轮流对一个数组玩游戏,第一个人可以把连续的一段为奇数的拿走,第二个可以拿走偶数的.
谁无法拿就输.
问谁能赢

Solution

如果和为奇数的话,则第一个人赢.
否则
如果n个数中没有奇数,则第二个人赢,
如果n个数中有一个奇数,那么第一个人取走它,剩下的数字还是奇数,这时候第二个人无论取还是不取,都只能减少偶数的和,剩下的肯定是奇数的和,那么第一个人就能一次性取走剩下的了。
因此第一个人赢.

NumberOf WA

0

Reviw

有意思

Code

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6;

int n,odd;
LL a[N+10];

int main(){
    //Open();
    //Close();
    ri(n);
    rep1(i,1,n) {
        rl(a[i]);
        if (a[i]&1) odd = 1;
    }
    LL sum = 0;
    rep1(i,1,n){
        sum += a[i];
    }
    sum&=1;
    if (sum == 1){
        puts("First");
    }else{
        if (!odd){
            puts("Second");
        }else{
            puts("First");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626112.html