Educational Codeforces Round 21 Problem D(Codeforces 808D)
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
3
1 3 2
YES
5
1 2 3 4 5
NO
5
2 2 3 4 5
YES
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left.
我很好奇,我和同学内部玩Virtual Contest的时候有个人读不懂前三题,偏偏这道题我读错了,他读懂。最后看到题目描述最后一句话中的element,单数!才发现只能移动一个,内心极其崩溃绝望,但还是在10分钟赶出了程序。
题目大意是说,给定一个数列,将一个数移动到另一个位置或者什么都不做,是否使得这个数列能被划分成2个部分。
记两个sum,一个是左边求和的sum,还有一个是另一边求和的sum。最开始左边的sum为0,右边的和为整个数列的和,然后依次将下一个数添加进左边,在右边删去这个数并修改sum,再判断两个sum是否相等,如果相等就可以简单地puts("YES"),然后exit(0)了,如果不相等,就判断差是否为奇数,如果不是就看看和大的那一边存不存在值为差的一半的数(存在就把它拿到小的那一边,就可以使和相等了),如果存在就输出YES退出程序。循环结束了,直接输NO就好了。
至于判断这个数存不存在,交给可重集就好了。
Code
/**
* Codeforces
* Problem#808D
* Accepted
* Time:15ms
* Memory:0k
*/
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef bool boolean;
#define inf 0xfffffff
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} #define LL long long int n;
int* a;
LL sum = ;
multiset<LL> s;
multiset<LL> s1, s2; inline void init() {
readInteger(n);
a = new int[(const int)(n + )];
for(int i = ; i <= n; i++) {
readInteger(a[i]);
sum += a[i];
s.insert(sum);
s2.insert(a[i]);
}
} LL sum1 = , sum2 = ; inline void solve() {
if(sum & ) {
puts("NO");
return;
}
sum2 = sum;
sum /= ;
if(s.count(sum)) {
puts("YES");
return;
}
for(int i = ; i <= n; i++) {
if(sum1 > sum2) {
LL temp = sum1 - sum2;
if((temp & ) == && s1.count(temp / )) {
puts("YES");
return;
}
} else {
LL temp = sum2 - sum1;
if((temp & ) == && s2.count(temp / )) {
puts("YES");
return;
}
}
sum1 += a[i], sum2 -= a[i];
s1.insert(a[i]), s2.erase(s2.find(a[i]));
}
puts("NO");
} int main() {
init();
solve();
return ;
}
Educational Codeforces Round 21 Problem D(Codeforces 808D)的更多相关文章
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
- Educational Codeforces Round 21 Problem A - C
Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...
- Educational Codeforces Round 21
Educational Codeforces Round 21 A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...
- Educational Codeforces Round 32 Problem 888C - K-Dominant Character
1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...
- Codeforces Round #524 (Div. 2) codeforces 1080A~1080F
目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)
A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- CF Educational Codeforces Round 21
A. Lucky Year time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- Oracle卸载之Linux下卸载oracle11g的方法
1.使用SQL*PLUS停止数据库 如果不能通过sysdba登陆可以用nolog用户登陆后切换至sysdba [oracle@OracleTest oracle]$ sqlplus /nolog S ...
- 网页设计师必知的10则SEO
如今,Web设计师在设计Web外观与风格的同时,往往还负责了前端代码的编写.换???话说,SEO的相当一部分责任是落在他们肩上的.然而,大 量的 Web设计师对SEO的熟悉程度仍不足以让他们写出一个符 ...
- java数据库三大范式
引用知乎网友@ 王红波的回答 一范式就是属性不可分割.属性是什么?就是表中的字段.不可分割的意思就按字面理解就是最小单位,不能再分成更小单位了.这个字段只能是一个值,不能被拆分成多个字段,否则的话,它 ...
- 洛谷P3368 树状数组2 树状数组+差分
正解:树状数组+差分 解题报告: 戳我! 不得不说灵巧真滴是越来越弱了...连模板题都要放上来了QAQ 因为今天考试的T3正解要用到树状数组这才惊觉树状数组掌握得太太太太差了...之前一直靠线段树续着 ...
- javaScript高级教程(一)javaScript 1.6 Array 新增函数
1.forEach,map,filter三个函数者是相同的调用参数.(callback[, thisArg]) callback is invoked with three arguments: th ...
- 【其他】csv文件打开是乱码,怎么办?
csv文件打开是乱码,怎么办?管用的方法,一个就够 工作中,将python生成的中间结果文件写入CSV,经常这么干是不是?文件保存下来后用excel打开,出现了乱码情况,真心烦.为什么? CSV是用U ...
- PHP移动互联网开发笔记(6)——MySQL数据库基础回想
近期看了一些架构方面的资料.可是发现基础知识都不怎么坚固,接下来的一段时间.我会定期总结基础知识. 一.数据类型 1.整型 数据类型 存储空间 说明 取值范围 TINYINT 1字节 很小的整 ...
- iphone传照片还是用QQ比较好
之前设置相机格式为高效,通过用91助手的苹果助手导出来文件格式为HEIC,window下没法打开.网上介绍用微信传,发现传的是缩略图,不清楚.最后选择通过qq传比较高清.注意,如果从相册中进行选择的话 ...
- nginx 11个处理阶段 && nginx lua 8个处理阶段
1. nginx 11 个处理阶段 nginx实际把请求处理流程划分为了11个阶段,这样划分的原因是将请求的执行逻辑细分,各阶段按照处理时机定义了清晰的执行语义,开发者可以很容易分辨自己需要开发的模块 ...
- There are 2 missing blocks. The following files may be corrupted
There are 2 missing blocks. The following files may be corrupted: 步骤1,检查文件缺失情况 可以看到, blk_1074785806 ...