cf 429 B. Godsend


昨晚的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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
现在需要统计若干段文字(英文)中的单词数量,并且还需统计每个单词出现的次数。 注1:单词之间以空格(1个或多个空格)为间隔。 注2:忽略空行或者空格行。 基本版: 统计时,区分字母大小写,且不删除指定标点符号。 进阶版: 统计前,需要从文字中删除指定标点符号!.,:*?。 注意:所谓的删除,就是用1个空格替换掉相应字符。 统计单词时需要忽略单词的大小写。 输入说明 若干行英文,最后以!!!!!为结束。 输出说明 单词数量 出现次数排名前10的单词(次数按照降序排序,如果次数相同,则按照键值的字母升序排序)及出现次数。 输入样例1 failure is probably the fortification in your pole it is like a peek your wallet as the thief when you are thinking how to spend several hard-won lepta when you are wondering whether new money it has laid background because of you then at the heart of the most lax alert and most low awareness and left it godsend failed !!!!! 输出样例1 46 the=4 it=3 you=3 and=2 are=2 is=2 most=2 of=2 when=2 your=2 输入样例2 Failure is probably The fortification in your pole! It is like a peek your wallet as the thief when You are thinking how to. spend several hard-won lepta. when yoU are? wondering whether new money it has laid background Because of: yOu?, then at the heart of the Tom say: Who is the best? No one dare to say yes. most lax alert and! most low awareness and* left it godsend failed !!!!! 输出样例2 54 the=5 is=3 it=3 you=3 and=2 are=2 most=2 of=2 say=2 to=2
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值