A. Cookies
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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?

Input

The first line contains the only integer n (1 ≤ n ≤ 100)
— the number of cookie bags Anna and Maria have. The second line contains nintegers ai (1 ≤ ai ≤ 100)
— the number of cookies in the i-th bag.

Output

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

Sample test(s)
input
1
1
output
1
input
10
1 2 2 3 4 4 4 2 2 2
output
8
input
11
2 2 2 2 2 2 2 2 2 2 99
output
1
题意:从一个数列中任取出一个数,使剩下的数的和是偶数,问共同拥有多少种取法。
O(n*n)算法 ,非常暴力。

。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
#define LL long long
int main()
{
int a[110],i,j,n,sum;
while(scanf("%d",&n)!=EOF)
{
int cnt=0;
for(i=0;i<n;i++)
scanf("%d",a+i);
for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<n;j++)
if(j!=i)
sum+=a[j];
if(sum%2==0)
cnt++;
}
printf("%d\n",cnt);
}
return 0;
}

Codeforces 129A-Cookies(暴力)的更多相关文章

  1. Karen and Game CodeForces - 816C (暴力+构造)

    On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...

  2. CodeForces 1099F - Cookies - [DFS+博弈+线段树]

    题目链接:https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting gam ...

  3. Chladni Figure CodeForces - 1162D (暴力,真香啊~)

    Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...

  4. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

  5. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  6. CodeForces - 589B(暴力)

    题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...

  7. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  9. CodeForces 156A Message(暴力)

    A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

随机推荐

  1. 洛谷3961 [TJOI2013]黄金矿工

    题目描述 小A最近迷上了在上课时玩<黄金矿工>这款游戏.为了避免被老师发现,他必须小心翼翼,因此他总是输.在输掉自己所有的金币后,他向你求助.每个黄金可以看做一个点(没有体积).现在给出你 ...

  2. info---Linux下info格式的帮助指令。

    info命令是Linux下info格式的帮助指令. 它的几个常用快捷键. ?键:它就会显示info的常用快捷键. N键:显示(相对于本节点的)下一节点的文档内容. P键:显示(相对于本节点的)前一节点 ...

  3. python 高阶函数 与关键字参数

    修饰器 之前我一直有一个疑惑,就是修饰器里面对函数的操作为什么不能直接写进函数里面就好了吗?何必这么麻烦呢,当我进一步理解之后,原来修饰器的作用就是完成那些不能写进函数里面的功能的,好比必须要等到函数 ...

  4. 第四讲 Yang-Mills方程与Maxwell方程

    一.变分原理 变分原理始于17世纪的速降问题,也就是连接两点的曲线在有重力的情况下,让初速度为0的一小球最快地通过? 这个问题由伯努力给出解答,他的方法非常巧妙,而最后开创了一个学科——变分学.他假设 ...

  5. 洛谷 P1176 路径计数2

    P1176 路径计数2 题目描述 一个N×N的网格,你一开始在(1, 1),即左上角.每次只能移动到下方相邻的格子或者右方相邻的格子,问到达(N, N),即右下角有多少种方法. 但是这个问题太简单了, ...

  6. UITextField监控文字变化方法

    项目里须要在不隐藏键盘的情况下.来更改button 的状态. 这里就是要对uitextfield监控.uitextfield继承于UIControl.所以能够 使用addTarget方法.详细例如以下 ...

  7. 异常Exception

    try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解.不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单.听话.不信?那你看 ...

  8. 在Ubuntu14.04中安装Py3和切换Py2和Py3环境

    前几天小编给大家分享了如何安装Ubuntu14.04系统,感兴趣的小伙伴可以戳这篇文章:手把手教你在VMware虚拟机中安装Ubuntu14.04系统.今天小编给大家分享一下在Ubuntu14.04系 ...

  9. 【Docker构建私有仓库】

    Docker默认不允许非HTTPS方式推送镜像,我们可以通过Docker的配置选项来取消此限制: [root@fedora ~]# cat /etc/docker/daemon.json { &quo ...

  10. python 发送邮件 <QQ+腾讯企业邮箱>

    一.使用QQ邮箱或者腾讯企业邮箱 python 发送邮件属于网络编程方向的,在工作中,我需要经常用邮件来检测我的程序运行状况.使用起来十分方便,这里我就用腾讯企业邮箱作为我的收发邮箱来使用. 使用py ...