http://codeforces.com/contest/808/problem/D

一开始是没什么想法的,然后回顾下自己想题的思路,慢慢就想出来了。首先要找到是否有这样的一个位置使得:

前缀和 == 后缀和,可以二分来求。

然后可以这样想,如果对于每一个数字,我都去移动一下,每个位置都试一下,复杂度多少?显然不能承受。

然后优化下这个思路,有了一点思路,优化到极致,看看能不能过,不能过就换思路吧。一般来说,每一个位置都试一下,是很没必要的。一般都是有一个位置是最优的。

这个位置就是放在最前或者放在最后。可以这样去想。

如果原来的数组,是不存在这样的位置的,那么移动a[i]到某一个位置后,存在了这样的位置。那么肯定是把这个数字移动去了前缀和的贡献哪里(后缀和同理),因为不是移动到前缀和哪里,就相当于没移。

所以把它移动到第1位,前缀和就肯定包含它了。

最后还是被hack,细节写歪了

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = + ;
int n;
int a[maxn];
LL sum[maxn];
LL nowDel;
LL ask(int pos) {
if (pos < nowDel) {
return sum[pos] - a[pos] + a[nowDel];
} else return sum[pos];
}
LL ask2(int pos) {
if (pos >= nowDel) {
return sum[pos] - a[nowDel] + a[pos + ];
} else return sum[pos];
}
bool tofind(int which) {
int be = , en = n;
while (be <= en) {
int mid = (be + en) >> ;
LL lef;
if (which == ) lef = ask(mid - );
else lef = ask2(mid - );
LL rig = sum[n] - lef;
if (lef < rig) be = mid + ;
else en = mid - ;
}
LL lef;
if (which == ) lef = ask(en);
else lef = ask2(en);
return lef * == sum[n];
}
void work() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
sum[i] = sum[i - ] + a[i];
}
// nowDel = 2;
// tofind(2);
for (int i = ; i <= n; ++i) {
nowDel = i;
if (tofind()) {
printf("YES\n");
return;
}
if (tofind()) {
printf("YES\n");
return;
}
}
printf("NO\n");
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

D. Array Division的更多相关文章

  1. 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 ...

  2. Array Division 808D

    D. Array Division time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

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

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

  4. Codeforces 808D. Array Division

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

  5. Educational Codeforces Round 21 D - Array Division (前缀和+二分)

    传送门 题意 将n个数划分为两块,最多改变一个数的位置, 问能否使两块和相等 分析 因为我们最多只能移动一个数x,那么要么将该数往前移动,要么往后移动,一开始处理不需要移动的情况 那么遍历sum[i] ...

  6. 【multimap的应用】D. Array Division

    http://codeforces.com/contest/808/problem/D #include<iostream> #include<cstdio> #include ...

  7. codeforces 808 D. Array Division(二分)

    题目链接:http://codeforces.com/contest/808/problem/D 题意:有一串长度为n的数组,要求选择一个数字交换它的位置使得这串数能够分成两串连续的和一样的数组. 这 ...

  8. Codeforces D. Array Division

    题目链接:http://codeforces.com/contest/808/problem/D 题意: 这一题给你一个数组,你可以调换某一个数的位置,使得这个数组可以分成2半,前半段的和等于后半段( ...

  9. CF808D STL

    D. Array Division time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. listen 73

    Give Time to Feel Less Time-Squeeze Meetings, calls, kids, dogs, errands, exercise—and all those ema ...

  2. hdu-5858 Hard problem(数学)

    题目链接: Hard problem Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  3. suse enterprise Linux 11上配置 oracle11g和tomcat开机自启动

    一.oracle 11g r2自启动 1.修改/etc/sysconfig/oracle文件: ORACLE_BASE=/oracle  //此处改为你安装的oracle目录 START_ORACLE ...

  4. jdk安装图解--windows系统(第一次安装和第二次安装区别)

    第一次安装可参考 https://jingyan.baidu.com/article/22fe7cedc9b93e3003617f64.html 第二次安装,如已经配置好环境变量,cmd下执行java ...

  5. jquery 插件 国外

    http://www.jqueryrain.com/demo/jquery-portfolio-gallery-plugin/

  6. oracle 内连接 外连接 查询 笔记

    elect ename,job,sal from emp where deptno>10 order by sal desc; 联合查询,PK dept.deptno FK emp.deptno ...

  7. java——构造方法重载

    class Person { private String name ; private int age ; public Person() { } public Person(String n,in ...

  8. Oracle&nbsp;11g&nbsp;R2安装手册(…

    1.Oracle 11g R2安装手册(图文教程)For Windows 1.下载Oracle 11g R2 for Windows版本,下载地址如下官方网站:http://download.orac ...

  9. qpython 读入数据问题: EOF error with input / raw_input

    直接使用input会报错 EOF error with input / raw_input 原因是在qpy里console mode 命令行模式不是完全和pc上的命令行一致,所以input和raw_i ...

  10. centos6.5安装gmime-2.6

    安装gmime库所需要的依赖库: 1 libffi库安装 简介:glib安装时依赖的库 解压: tar xf libffi-3.0.0.tar.gz 进入目录: cd libffi-3.0.0 安装: ...