CSU-2220 Godsend

题目链接

http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2220

题目

Description

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 ≤ 1000000) — length of the array.

Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 1000000000).

Output

Output answer in single line.

"First", if first player wins, and "Second" otherwise (without quotes).

Sample Input

4
1 3 2 3

Sample Output

First

题意

两个人进行游戏,给定n和n个数字,第一个人可以拿走和为奇数的一部分数字,第二个人可以拿走和为偶数的一部分数字,谁不能拿走数字则输,问谁能赢

题解

博弈论入门题目,若所有数和为奇数,那么先手可以直接拿走所有数字,后手输,若和为偶数,那么先手可以先拿走一个奇数,此时和为奇数,后手只能拿走和为偶数的部分,剩下的数仍为奇数,先手全部拿走,先手赢,若没有一个奇数全为偶数,先手无法拿走数字,后手赢。

总结一下,即数列中有奇数,先手赢,否则后手赢

AC代码

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a;
		scanf("%d", &a);
		if (a % 2 == 1) {
			printf("First");
			return 0;
		}
	}
	printf("Second");
	return 0;
}
/**********************************************************************
	Problem: 2220
	User: Artoriax
	Language: C++
	Result: AC
	Time:180 ms
	Memory:2024 kb
**********************************************************************/

原文地址:https://www.cnblogs.com/artoriax/p/10370731.html