Codeforces 129A-Cookies(暴力)
2 seconds
256 megabytes
standard input
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?
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.
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
1
1
1
10
1 2 2 3 4 4 4 2 2 2
8
11
2 2 2 2 2 2 2 2 2 2 99
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(暴力)的更多相关文章
- 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 ...
- CodeForces 1099F - Cookies - [DFS+博弈+线段树]
题目链接:https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting gam ...
- Chladni Figure CodeForces - 1162D (暴力,真香啊~)
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...
- 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 ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- CodeForces - 589B(暴力)
题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...
- CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
- 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 ...
- CodeForces 156A Message(暴力)
A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
随机推荐
- Java基础学习总结(21)——数组
一.数组的基本概念 数组可以看成是多个相同类型数据组合,对这些数据的统一管理. 数组变量属引用类型,数组也可以看成是对象,数组中的每个元素相当于该对象的成员变量. 数组的元素可以是任何数据类型,包括基 ...
- 思考一下activity的启动模式
在android里,有4种activity的启动模式.分别为:"standard" (默认) "singleTop" "singleTask" ...
- php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等
php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等 <?php header("Content-type: text/html; charset=utf-8" ...
- C++ BigInteger模板
#include <cstdio> #include <cstring> #include <string> #include <iostream> # ...
- 远程带参数POST访问接口,返回数据
1. string token = GetRequest.GetString("token"); int customer_id = GetRequest.GetInt(" ...
- Web API总结
1.Web API 控制器(Controller) 继承ApiController 2. Api 的 Url Map: api/{controller}/{id} 每个"Action&quo ...
- HDU 3374 String Proble
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Bit、Byte、kb、KB、MB、KiB、MiB各表示什么意思?
1.Byte.bit:bit表示:位,是计算机中最小的数据单位.每一位的状态只能是0或1Byte表示:字节,8个二进制位构成1个字节,即1 Byte = 8 bit .1个英文字母或者数字占用1个字节 ...
- 研究一些复杂java开源软件代码的体会(转)
原文地址:http://herman-liu76.iteye.com/blog/2349026 有时候看源代码是非常有趣的事情,象是思考游戏,象是思考棋局... 平时做J2EE项目中, ...
- Vijos——T1406 拉力赛
https://vijos.org/p/1460 描述 车展结束后,游乐园决定举办一次盛大的山道拉力赛,平平和韵韵自然也要来参加大赛. 赛场上共有n个连通的计时点,n-1条赛道(构成了一棵树).每个计 ...