Codeforces Round#429 B-Godesend

来源:互联网 发布:python 微信报警接口 编辑:程序博客网 时间:2024/06/07 02:41

题意&分析:
题目传送门
First选手可以取走数组中一段和为奇数的子串,Second取走的是和为偶数的子串,取走后剩余部分合并成新的数组。谁不能再取则输。

若全部和为奇数,First直接获胜。
若为偶数,只需要判断数组中是否有奇数,若有,则First取走后剩余部分和任为奇数,取走一段偶数部分的和,剩余依然是奇数。

代码如下:

#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define TEST cout<<"stop here"<<endl using namespace std;typedef long long ll;const ll mod = 1e9 + 7;int main(){    std::ios::sync_with_stdio(false);    std::cin.tie(0);    int n;    while(cin>>n){        int ans = 0,flag = 0;        for(int i=0;i<n;i++){            ll x;            cin>>x;            if(x%2==1){                flag = 1;                ans++;            }        }        if(!ans && !flag)            cout<< "Second" <<endl;        else cout<< "First" <<endl;    }    return 0;}
原创粉丝点击