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 ...
随机推荐
- POJ-2393 Yogurt factory 贪心问题
题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...
- 新人 记录VUE中分页实现
关于函数传值 this.getPurchaseHistoryData(index, num,timeType);第一位是显示的页数,第二是控制首页4上一页-1下一页是2末页是5 第三是是对昨天是1,今 ...
- 洛谷——P1019 单词接龙(NOIP2000 T3)
https://www.luogu.org/problem/show?pid=1019#sub 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母, ...
- linux中的硬连接和软连接
linux中的硬连接和软连接 linux中的硬连接和软连接 背景 连接 硬连接 软连接 example reference 背景 linux中的文件主要分3块, - 真正的数据 - 索引节点号(ino ...
- shell 脚本去掉月份和天数的前导零
#!/bin/sh # # shell 脚本去掉月份和天数的前导零 # 前面填 1 变成百位数,然后减 100 # 去掉前导零的通用方法 $((10#$(date +%m))) # 把字符串分割成数组 ...
- Ubuntu 16.04/18.04 LTS改变时区和语言
Ubuntu 16.04/18.04 LTS改变Timezone时区设定原文 https://www.phpini.com/linux/ubuntu-16-04-change-timezone-set ...
- Gym - 100625J Jailbreak 最短路+搜索
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
- 转:Java读写文件各种方法及性能比较
干Java这么久,一直在做WEB相关的项目,一些基础类差不多都已经忘记.经常想得捡起,但总是因为一些原因,不能如愿. 其实不是没有时间,只是有些时候疲于总结,今得空,下定决心将丢掉的都给捡起来. 文件 ...
- codefroces 873 B. Balanced Substring && X73(前缀和思想)
B. Balanced Substring You are given a string s consisting only of characters 0 and 1. A substring [l ...
- 联想 Thinkserver TS250服务器RAID1 重建测试
1.RAID1状态下,拨掉其中一块硬盘后,RAID1即失效. 2.重新插入后,在进行系统后会自动重建 *RAID1 提示Rebuild *进入桌面后软件,显示重建进度 软件下载地址:https://p ...