464 Cookies【水题】

Cookies

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 1
描述
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
输入
The first line contains the only integer n (1 ≤ n ≤ 100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1 ≤ ai ≤ 100) — the number of cookies in the i-th bag.Cases will be end with EOF.
输出
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
样例输入
1
1
10
1 2 2 3 4 4 4 2 2 2
11
2 2 2 2 2 2 2 2 2 2 99
样例输出
1
8
1


比较简单的一道题,题目要求的少,所以处理也简单了,刚开始没看懂题意,感觉很难,然后思考一下,原来这么简单啊,然后秒a.....


就是求出去掉一列数中的某一个值后,剩下的和是偶数,一共有几种选法....比较直观的方法就是循环枚举一下,数据量小,不怕超时..


#include<stdio.h>
int main()
{
	int x[105],n;
	//freopen("shuju.txt","r",stdin);
	while(~scanf("%d",&n))
	{
		int sum=0,cnt=0,i;
		for(i=0;i<n;++i)
		{
			scanf("%d",x+i);
			sum+=x[i];
		}
		for(i=0;i<n;++i)
		{
			if((sum-x[i])%2==0)
			{
				++cnt;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值