【CF Round 429 B. Godsend】
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output
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
input
4
1 3 2 3
output
First
input
2
2 2
output
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.
【翻译】输入一个长度为n的序列,第一个人和第二个人轮流操作,第一个人先操作。第一个人可以取走和为奇数的连续一段,第二个人可以取走和为偶数的连续一段,但是不能不去。两人采取最优策略,最终谁会赢(第一个赢输出Fires,反之输出Second)。
题解:
①分类讨论就可以了:
(1)如果整个序列和为奇数,那么开局First就胜利了。
(2)如果整个序列和为偶数:
[1]如果这个序列没有奇数,那么First没法取,Second赢了。
[2]如果存在奇数,那么必会有偶数个奇数,那么First每次只消去一个奇数,到最后一定是他赢,因为Second始终没法消去奇数个奇数。
#include<stdio.h>
int main()
{
int n,sum=0,_=0,a;scanf("%d",&n);
while(n--)scanf("%d",&a),sum+=a,a&1?_=1:1;
puts(sum&1||_?"First":"Second");return 0;
}//Paul_Guderian
祝母校60岁生日快乐!———Rice_Rabbit
【CF Round 429 B. Godsend】的更多相关文章
- 【CF Round 434 A. k-rounding】
Time limit per test1 second memory limit per test 256 megabytes input standard input output standard ...
- 【Codeforces Round #429 (Div. 2) B】 Godsend
[Link]:http://codeforces.com/contest/841/problem/B [Description] 两个人轮流对一个数组玩游戏,第一个人可以把连续的一段为奇数的拿走,第二 ...
- 【CF Round 434 B. Which floor?】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF Round 439 E. The Untended Antiquity】
time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standa ...
- 【CF Round 439 C. The Intriguing Obsession】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF Round 439 B. The Eternal Immortality】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【CF Round 439 A. The Artful Expedient】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...
- 【Codeforces Round #429 (Div. 1) B】Leha and another game about graph
[链接]点击打开链接 [题意] 给出一个连通图,并给每个点赋一个d值0或1或-1,要求选出一个边的集合,使得所有的点i要么d[i] == -1,要么 dgree[i] % 2 == d[i],dgr ...
随机推荐
- Java之 jstl 自定义标签的方法
1.写一个Java类 我的路径是写再tag包中的一个 HelloTag类 package tag; import java.io.IOException; import javax.servlet.j ...
- vue笔记v-bind
把message的信息绑定给title,运行出来的结果是<span title="you loaded this page on +Mon Nov 21 2016 18:28:38 G ...
- python__基础 : 异常处理与自定义异常
异常处理方法一般为: try: ------code----- except Exception as e: # 抛出异常之后将会执行 print(e) else: # 没有异常将会执行 print( ...
- zookeeper集群(二)
经过前一篇文章<zookeeper伪集群一>的阅读,相信大家对zookeeper集群已经有一定的了解了,接下来我们再谈谈zookeeper真集群.其实真集群和伪集群还是有很多相似的部分的, ...
- scrapy之分布式
分布式爬虫 概念:多台机器上可以执行同一个爬虫程序,实现网站数据的分布爬取. 原生的scrapy是不可以实现分布式爬虫? a) 调度器无法共享 b) 管道无法共享 工具 scrapy-redis组件: ...
- WPF Datagrid对鼠标单击进行响应,借助EventSetter
在做的一个c#的项目中发现Datagrid没办法直接对鼠标单击进行响应, 调用MouseDown事件也需要点击某一行第二次才能响应. 所以借助EventSetter来简单的实现了一个. 界面部分的代码 ...
- POJ 3662 (二分+SPFA
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8856 Accepted: 3211 D ...
- POJ:3061-Subsequence(尺取法模板详解)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18795 Accepted: 8043 Descript ...
- 笔记-python-module导入技巧
笔记-python-module导入技巧 1. module导入技巧 1.1. 控制模块导入内容 在模块中定义 __all__ = [] 不多言,主要是影响from <> ...
- 在ddms 里面查看data/data里面的东西 不显示data/data
今天我要查看data/anr/tarces.txt,没办法,我只有root手机. 可是root之后,我发现还是不能查看或者导出traces.txt. 后来我才知道,root之后,文件夹权限没有变,所以 ...