题目链接:http://codeforces.com/contest/808/problem/D

题意:

  这一题给你一个数组,你可以调换某一个数的位置,使得这个数组可以分成2半,前半段的和等于后半段(严格的前半段和后半段)。问你能不能构成。

题解:

  一开始读题的时候,被吓坏了,没有看到是移动一个,因为题目在output那里才有写是移动一个。

  那么如果这个和是奇数的话,就无法分成2个相等的部分。则是NO。

  如果这个数列里有一个数是sum/2的话也是YES。

  如果是移动一个数,那么这个数一定在某一个大于sum/2的前缀和里或者是在某一个大于sum/2的后缀和里面。因为大于sum/2的时候一定要移动一个数,才能是前缀和为sum/2。

  同理从后面来看也是这样。

  我们就可以用一个set来保存前面出现过的ai 

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
typedef unsigned long long ULL;
const int inf = 0x3f3f3f3f;
const LL INF = 0x7fffffff;
const int maxn = 1e5+;
const int mod = 1e9+;
LL a[maxn];
void init()
{ }
void solve()
{
ios::sync_with_stdio(); int n;
LL sum = ;
cin >> n;
for(int i = ;i<=n;i++) cin >> a[i], sum+=a[i];
if(sum%==){
cout << "NO" << endl;
return;
}
sum /= ;
for(int i = ;i<=n;i++){
if(a[i] == sum) {
cout << "YES" << endl;
return;
}
}
LL x = ;
set<LL> S;
for(int i = ;i<=n;i++){
x += a[i];
S.insert(a[i]);
if(S.count(x - sum)){
cout << "YES" << endl;
return;
}
}
S.clear();
for(int i= n;i>;i--){
x -= a[i];
S.insert(a[i]);
if(S.count(sum-x)){
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
solve();
return ;
}

你努力的时候,比你厉害的人也在努力。

Codeforces D. Array Division的更多相关文章

  1. Codeforces 808D. Array Division

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

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

  3. Array Division 808D

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

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

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

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

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

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

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

  7. Codeforces 797E - Array Queries

    E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...

  8. Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力

    Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...

  9. CodeForces - 1175D Array Splitting(数组划分+后缀和+贪心)

    You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array in ...

随机推荐

  1. discover面试

    电话面 英语 20191009 面试我的是一个小姐姐,她是数据挖掘分析师,声音很甜很好听.全程英文 (1)please introduce yourself in two minutes (2)我对你 ...

  2. boost的libboost_system问题

    最近把cpp代码从开发机放到eclipse时,遇到了不少路径问题. 安装boost的时候,其实很简单 wget http://sourceforge.net/projects/boost/files/ ...

  3. [Web 前端] 004 html 小练习

    1. 锚点 用法 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  4. 一个阿里云apache服务器配置两个或多个域名forLinux

    一个阿里云apache服务器配置两个或多个域名for Linux: 默认已经配置好了阿里云提供的一键web安装,可以参考:http://www.42iot.com/?id=8 修改/alidata/s ...

  5. OtterTune配置记录

    0. 准备两台Ubuntu 18.04的虚拟机,安装mysql(供server-side存储调优数据用)和postgresql(供client-side存储业务数据用,这里以PostgreSQL为例. ...

  6. AppDomain (转)

    AppDomain是CLR的运行单元,它可以加载Assembly.创建对象以及执行程序.AppDomain是CLR实现代码隔离的基本机制. 每一个AppDomain可以单独运行.停止:每个AppDom ...

  7. js中的函数声明置顶

    函数声明置顶是指 js引擎在读取变量与声明式函数时,会优先读取,例如如下 var a = 1: function a(){}; console.log(a); //这里得到的为1,而不是该functi ...

  8. intel vtune 介绍、安装和使用

    intel vtune 介绍 https://software.intel.com/en-us/vtune intel vtune 安装包下载地址 https://software.intel.com ...

  9. 【爬虫】Selenium+chrome

    一.下载对应chrome版本的webdriver https://npm.taobao.org/mirrors/chromedriver 二.pom <dependency> <gr ...

  10. [sqlmap源码阅读] 数据库识别

    通过网页返回的数据库错误信息识别网站所有数据库类型,用到的正则表达式及支持识别的数据库类型,这些信息以xml文件的形式存在,使用 sax 解析xml.