题意:给出一个序列,询问是否能移动一个数(或不操作)使得序列能分为左右两个和相等的子序列。
思路:对每个数处理最左边和最右边出现的位置。设置断点分左右区间,左右区间和差值的一半就是要找的数,进行判断。

tip:很简单的想法,但debug很久很久,细节部分考虑欠妥。忘记位运算的优先级很低,sub&1==1错误,l[sub]<=i时漏考虑sub不出现时l[sub]都为0,发生错误。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
map<ll,int> l,r;
int a[N];
int main() {
int n;scanf("%d",&n);
ll sum=0;
for(int i=1;i<=n;++i) {
scanf("%d",&a[i]);
sum=0ll+sum+a[i];
if(!l[a[i]]) l[a[i]]=i,r[a[i]]=i;
else r[a[i]]=i;
}
ll t=0;
int f=0;
for(int i=1;i<=n && !f;++i) {
t=0ll+t+a[i];
ll sub=abs(sum-t-t);
if(!sub) {
f=1;break;
}
if((sub&1)==1) continue;
sub/=2ll;
if(sum-t-t>0&&(r[sub]>i)) f=1;
else if(sum-t-t<0&&(l[sub]<=i&&l[sub]!=0)) f=1;
}
if(f) puts("YES");
else puts("NO");
return 0;
}

codeforces 808D的更多相关文章

  1. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  2. Array Division CodeForces - 808D (构造+实现)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  3. Codeforces 808D. Array Division

    题目大意 给定你一个长为\(n\)的序列,问能否在最多一次取出某一元素然后插入到某一点后可以将整个序列分成两段使得其两段的元素之和相同. \(n \leq 10^5\) 题解 发现插入操作实际上是让某 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. md5 算法类 java

    package com.sunyard.p2p.util; import java.security.MessageDigest; import java.security.NoSuchAlgorit ...

  2. Openstack块存储cinder安装配置

    openstack service create --name cinderv2 \ --description "OpenStack Block Storage" volumev ...

  3. Making training mini-batches

    Here is where we'll make our mini-batches for training. Remember that we want our batches to be mult ...

  4. 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280

    POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...

  5. Linux基础服务

    作业一:nginx服务1.二进制安装nginx包 [root@bogon ~]# systemctl disable firewalld #关闭Firewalld自启动 Removed symlink ...

  6. 解决:function in namespace ‘std’ does not name a type + allocator_/nullptr/dellocator_ was not declared + base operand of ‘->’ has non-pointer type ‘std::vector<cv::Mat>’ 错误编译时报错(caffe)

    解决方法,用到了c++11,g++命令需要加上-std=c++11选项 附:g++默认的c++标准 gcc-6.4.0 gcc-7.2.0 默认是 -std=gnu++14gcc-4.3.6 gcc- ...

  7. rest_framework之访问频率控制

    一  自定义频率控制类 class MyThrottle(): visitor_dic = {} def __init__(self): self.history = None def allow_r ...

  8. Js 实现ajax

    一.JS实现的ajax 1.AJAX核心(XMLHttpRequest) 其实AJAX就是在Javascript中多添加了一个对象:XMLHttpRequest对象.所有的异步交互都是使用XMLHtt ...

  9. fopen() r+、w+属性详解

    r+具有读写属性,从文件头开始写,保留原文件中没有被覆盖的内容: w+具有读写属性,写的时候如果文件存在,会被清空,从头开始写. r 打开只读文件,该文件必须存在. r+ 打开可读写的文件,该文件必须 ...

  10. (4.8)SET ANSI_NULLS ON、SET QUOTED_IDENTIFIER ON

    T-SQL支持在与空值进行比较时,允许比较运算符返回 TRUE 或 FALSE. 通过设置 ANSI_NULLS OFF 可将此选项激活.当 ANSI_NULLS 为 OFF 时,如果 ColumnA ...