B. Godsend
来源:互联网 发布:数据结构c语言课程设计 编辑:程序博客网 时间:2024/06/07 14:33
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?
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 answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
41 3 2 3
First
22 2
Second
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.
水题,不要想复杂了。一开始是先取奇数,所以如果sum是奇数,就可以直接取完,如果sum是偶数的话,我们看看里面是不是有奇数,如果有奇数的话,肯定就是奇数赢了,因为剩下的是奇数,另外一个人只能是偶数,所以剩下的还是奇数,所以这样的话,就是奇数的赢。但是,如果里面没有奇数,就是偶数赢了。
#include <iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<map>#include<string.h>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;const int maxn=1e6+10;int num[maxn];int main(){ int n; scanf("%d",&n); int flag_odd=0; ll sum=0; for(int i=1;i<=n;i++) { scanf("%d",&num[i]); sum += num[i]; if(num[i]%2!=0) flag_odd=1; } if(sum%2==1||flag_odd) printf("First\n"); else printf("Second\n"); return 0;}
- B. Godsend
- B. Godsend
- 429B. Godsend
- codefroces 841B Godsend
- cf 429 B. Godsend
- codeforces 841B Godsend
- Codeforces 841 B Godsend
- Codeforces 841B Godsend
- CodeFroces 429B Godsend (模拟)
- Codeforces-429-2-B Godsend
- Codeforces Round #429 (Div. 2):B. Godsend
- Codeforces Round #429 (Div. 2) | B. Godsend
- B. Godsend(Round #429 (Div. 2))
- Codeforces Round #429 (Div. 2) 841B Godsend(思维)
- Codeforces Round #429(Div.2) B Godsend 博弈
- codeforces Div.2 #429 B.Godsend C. Leha and Function
- Godsend CodeForces
- cf841A Godsend
- malloc/free和new/delete
- 【离散化+并查集】POJ_1733_Parity game
- CSS3基础学习 02-应用方式:内联、内部、外部
- Lua5.3 虚拟机指令分析(一)概述
- 涉及AbstractQueuedSynchronizer使用-CountDownLatch等
- B. Godsend
- Java中转换字符串编码
- 传感器项目框架1
- Android Studio中的神操作
- MAVEN配置pom.xml名词解释
- 429A. Generous Kefa
- uva 11582 快速幂 Fibonacci循环节
- CentOS 6使用openssl搭建根CA
- 01背包问题之二 (动态规划(DP))