Codeforces Round #248 (Div. 2) A. Kitahara Haruki's Gift
来源:互联网 发布:王侯将相宁有种乎读音 编辑:程序博客网 时间:2024/05/29 12:04
A. Kitahara Haruki's Gift
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100or wi = 200), where wi is the weight of the i-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
3100 200 100
YES
4100 100 100 200
NO
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
解题说明:此题的意思是平分一组数,由于只有100和200两个数值,简单判断就会发现首先100出现次数为奇数,或者100未出现200出现奇数次的情况下都不符合要求,其余情况均能够实现均分。
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<cstdlib>
- #include <algorithm>
- #include<cstring>
- #include<string>
- using namespace std;
- int main()
- {
- int n, a = 0;
- int i, w;
- scanf("%d", &n);
- for (i = 0; i<n; i++)
- {
- scanf("%d", &w);
- if (w == 100)
- {
- a++;
- }
- }
- if (a % 2 == 1 || (n % 2 == 1 && a == 0))
- {
- printf("NO\n");
- }
- else
- {
- printf("YES\n");
- }
- return 0;
- }
- Codeforces Round #248 (Div. 2) A - Kitahara Haruki's Gift
- Codeforces Round #248 (Div. 2) A. Kitahara Haruki's Gift
- Codeforces Round #248 (Div. 2) A - Kitahara Haruki's Gift
- Codeforces 433A Kitahara Haruki's Gift
- Codeforces 433A Kitahara Haruki's Gift
- CodeForces 433A Kitahara Haruki's Gift
- CodeForces 433A. Kitahara Haruki's Gift
- CF #248 A. Kitahara Haruki's Gift
- A. Kitahara Haruki's Gift
- codeforces#248_div2_A Kitahara Haruki's Gift dp
- CF#248DIV2:A. Kitahara Haruki's Gift
- Codeforces Round #286 (Div. 2)-A. Mr. Kitayuta's Gift
- Codeforces Round #286 (Div. 2) A. Mr. Kitayuta's Gift
- Codeforces Round #286 (Div. 2) A - Mr. Kitayuta's Gift ( 暴力枚举)std:string::insert
- 暴力字符串 Codeforces Div. 2 A Mr. Kitayuta's Gift
- Codeforces Round #156 (Div. 2)---A. Greg's Workout
- Codeforces Round #368 (Div. 2) A Brain's Photos
- Codeforces Round #368 (Div. 2)(A. Brain's Photos)
- 主宰全球的10大算法
- Oracle索引-2
- 二叉堆
- 数字金额转化为大写金额
- 33333333333333333333333333333
- Codeforces Round #248 (Div. 2) A. Kitahara Haruki's Gift
- 几种Android设备在Mac OS X下Adb 联接方法
- pagerank算法java实现
- 网盘背后的秘密(稍作修改)
- windows进程间通信系列 第一篇——概述
- 解决搜狗输入法启用qimpanel的问题
- 用java实现:根据用户输入的年份打印该年的日历
- 各种大神博客收集贴
- Socket网络编程学习之路 第一篇-----学习感悟