CodeForces - 841B-Godsend-思维
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 ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
Examples
4
1 3 2 3
First
2
2 2
Second
Note
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
1 #include<stdio.h> 2 #include<map> 3 #include<iostream> 4 #include<string.h> 5 #include<algorithm> 6 #include<stack> 7 #include<cmath> 8 #include<vector> 9 using namespace std; 10 typedef long long ll; 11 12 13 int a[1000020]; 14 15 int main() 16 { 17 int n; 18 while(cin>>n) 19 { 20 ll sum=0; 21 int flag=0; 22 for(int i=0;i<n;i++) 23 { 24 cin>>a[i]; 25 if(a[i]%2==1) 26 flag=1; 27 sum+=a[i]; 28 } 29 if(sum%2==1) 30 cout<<"First"<<endl; 31 else 32 { 33 if(flag==0) 34 cout<<"Second"<<endl; 35 else 36 cout<<"First"<<endl; 37 } 38 39 } 40 return 0; 41 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」