昨晚的cf测试B问题。在做题的时候看到题目首先想到的是用线段树解决,建完树之后发现懵逼了,接下来怎么办啊
。。。。。然后就没有然后了,放弃了这题去做后面的题目了。今天起床后有想了下这题,真是被自己蠢哭了,哈哈哈哈。下面讲下这题的思路。
首先这是一道博弈论的题。两个人可以从连续整数中选择一段连续子序列,第一个人选的和必须是奇数,第二个人必须是偶数,依次交替。当选到下一个人没得选的时候,这个人就赢了。
首先假设当前整数序列中奇数个数为x个:
x=0:肯定是选偶数的那个赢啊,因为第一个人怎么选都选不出来一个和为奇数的序列。
x=1:第一个人可以把整个序列全选完,那。。。。。。。。。。第二个人就没有数给他选了,所以第一个赢。
x=2:第一个人先随便选一个奇数,现在只剩一个奇数。因为第二个人不能选择包含奇数的序列,所以第二个人选完之后事件变成第一种情况,第一个人赢。
x=3:等同于第一种。
x=4:等同于第二种。
.
.
.
.
所以,这题实际上是只要有奇数就是第一个人赢。
下面代码我想可能都不想看了
#include<iostream>
using namespace std;
int main()
{
int n;
bool flag=false;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int t;
scanf("%d",&t);
if(t%2==1)
flag=true;
}
if(flag==true)
printf("First\n");
else
printf("Second\n");
return 0;
}