NYOJ 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

总重为奇数则拿数量为奇数(odd)的袋子,总重为偶数则拿数量为偶数的袋子

#include<iostream>  

using namespace std;
int main()  
{  
int n,sum,i,odd,even,a[110];  
while(cin>>n)  
{  
sum=even=odd=0;  
for(i=0;i<n;i++)  
{  
cin>>a[i]; 
sum+=a[i];  
if(a[i]%2==1)  
odd++;  
else  
even++;  
}  
if(sum%2==1)
cout<<odd<<endl;
else
cout<<even<<endl;
}  
return 0;  
}  

猜你喜欢

转载自blog.csdn.net/tingtingyuan/article/details/80149701