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

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. Date类、DateFormat类和Calendar类

    1.Date类 常用方法:long getTime():返回1970年1月1日00:00:00以来的毫秒值,把日期对象转换成毫秒值 2.DateFormat类 DateFormat类是日期/时间格式化 ...

  2. cocos2d安卓自动编译脚本去掉复制Resources资源和签名功能

    去掉这两个功能的原因: 1.因为有时候打包是分渠道的,不同的渠道资源也可能不一样,所以不能直接复制资源. 2.如果用cocostudio打release包,因为要输入签名地址,会导致在自动签名处停住不 ...

  3. Android无线测试之—UiAutomator UiObject API介绍四

    输入文本与清除文本 一.输入文本与清除文本相关API 返回值 API 描述 boolean setText(String test) 在对象中输入文本 void clearTextField() 清除 ...

  4. SPOJ OPTM - Optimal Marks

    OPTM - Optimal Marks no tags  You are given an undirected graph G(V, E). Each vertex has a mark whic ...

  5. storyboard设置navigation controller

    到storyboard选中我们唯一一个的viewcontroller,找到xcode的菜单栏,Edit->Embed In->NavigationController.这时候storybo ...

  6. iOS tableview滑动到底部自动加载,向上拽加载

    - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { CGPoint offset = aScrollView.contentOffset ...

  7. oracle的order by decode根据文字自定义排序的例子

    oracle的order by decode根据文字自定义排序的例子: order by decode(t.title, '当前生效预警', 1, '今日即将生效', 2, '明日预计生效', 3, ...

  8. Python全栈day24(面向对象编程作业作业_定义学校老师课程班级学生类)

    面向对象作业 作业_定义学校老师课程班级学生类.py #面向对象编程作业,定义学校老师课程班级学生类 #定义几个类,尽可能定义多的数据属性及函数属性 class School: def __init_ ...

  9. 面试题15:链表中倒数第K个结点

    输入一个链表,输出该链表中倒数第k个结点. 方法1: 这个解法要循环两次链表 /* public class ListNode { int val; ListNode next = null; Lis ...

  10. TempData、ViewData和ViewBag异同

    Data ViewData ViewBag都可以用来保存数据. 它们之间的区别如下: TempData:保存在Session中,Controller每次执行请求的时候,会从Session中先获取Tem ...