codeforces 808D
题意:给出一个序列,询问是否能移动一个数(或不操作)使得序列能分为左右两个和相等的子序列。
思路:对每个数处理最左边和最右边出现的位置。设置断点分左右区间,左右区间和差值的一半就是要找的数,进行判断。
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的更多相关文章
- 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 ...
- Array Division CodeForces - 808D (构造+实现)
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...
- Codeforces 808D. Array Division
题目大意 给定你一个长为\(n\)的序列,问能否在最多一次取出某一元素然后插入到某一点后可以将整个序列分成两段使得其两段的元素之和相同. \(n \leq 10^5\) 题解 发现插入操作实际上是让某 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- Java Base64解析
最近在业务场景中,需要对第三方传递进来的字符进行base64解密,根据第三方文档提供的解析工具,对数据进行了解析,关于Base64的解析方式如下: String sign = "xxxxxx ...
- BF算法 + KMP算法
准备: 字符串比大小:比的就是字符串里每个字符的ASCII码的大小.(其实这样的比较没有多大的意义,我们关心的是字符串是否相等,即匹配等) 字符串的存储结构:同线性表(顺序存储+链式存储) 顺序存储结 ...
- js获取上个月的第一天和最后一天
var now = new Date(); var fd = new Date(now.getFullYear(), now.getMonth()-1 ,1).toLocaleDateString() ...
- JZOJ.5274【NOIP2017模拟8.14】数组
Description
- float元素一定要闭合
float:left; float:right; 一定要两个元素一起放float
- HYSBZ 2160 拉拉队排练(回文树)
2160: 拉拉队排练 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 825 Solved: 324 [Submit][Status][Discu ...
- python中matplotlib绘图封装类之折线图、条状图、圆饼图
DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...
- PHP使用SimpleElement创建和解析xml文件
<!-- 使用SimpleXMLElement生成xml文件 --><?php//生成一个xml文件 //xml字符串$_xml = <<<_xml<?xml ...
- SQL Server常用函数汇总
1.day(date) 用途:获取日期是所在月的几号 参数:date是一个可以解析为 time.date.smalldatetime.datetime.datetime2 或 datetime ...
- js对象转成用&拼接的请求参数(转)
var parseParam=function(param, key){ var paramStr=""; if(param instanceof String||param in ...