Splitting Pile
Splitting Pile
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer ai written on it.
They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x−y|. Find the minimum possible value of |x−y|.
Constraints
- 2≤N≤2×105
- −109≤ai≤109
- ai is an integer.
Input
Input is given from Standard Input in the following format:
N
a1 a2 … aN
Output
Print the answer.
Sample Input 1
6
1 2 3 4 5 6
Sample Output 1
1
If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x−y|=1. This is the minimum possible value.
Sample Input 2
2
10 -10
Sample Output 2
20
Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=−10, and thus |x−y|=20.
题意:一共有n张牌,A拿走前面的至少一张,最多只剩一张,B拿走剩下的,问他们各自的牌的和的绝对值差最小是多少?
直接暴力得了,把所有能拿的情况都列出来,然后排个序ok
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 200010 LL a[MX];
LL ans[MX]; int main()
{
int n;
scanf("%d",&n);
LL sum=;
for(int i=;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
LL x = a[];
LL y = sum-a[];
ans[]=abs(x-y);
for (int i=;i<n-;i++)
{
x+=a[i];
y-=a[i];
ans[i]=abs(x-y);
}
sort(ans,ans+n-);
cout<<ans[]<<endl;
return ;
}
Splitting Pile的更多相关文章
- Splitting Pile --AtCoder
题目描述 Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer ai written ...
- AtCoder Beginner Contest 067 C - Splitting Pi
C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...
- AtCoder Regular Contest 078
我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...
- 【AtCoder】ARC078
C - Splitting Pile 枚举从哪里开始分的即可 #include <bits/stdc++.h> #define fi first #define se second #de ...
- AtCoder Regular Contest 078 C
C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...
- 关于 Word Splitting 和 IFS 的三个细节
在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...
- Educational Codeforces Round 4 A. The Text Splitting 水题
A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...
- bzoj4578: [Usaco2016 OPen]Splitting the Field
2365: Splitting the Field 题意:n个点,求用两个矩形面积覆盖完所有点和一个矩形覆盖完少多少面积 思路:枚举两个矩形的分割线,也就是把所有点分成两个部分,枚举分割点:先预处理每 ...
- [Webpack 2] Maintain sane file sizes with webpack code splitting
As a Single Page Application grows in size, the size of the payload can become a real problem for pe ...
随机推荐
- Mycat探索之旅(4)----Mycat的自增长主键和返回生成主键ID的实现
说明:MyCAT自增长主键和返回生成主键ID的实现 1) mysql本身对非自增长主键,使用last_insert_id()是不会返回结果的,只会返回0:这里做一个简单的测试 创建测试表 ------ ...
- python 使用 urllib2
使用basic auth 的3种方式 1. 设置header import urllib2 from base64 import encodestring headers = {'Content-Ty ...
- Django——基于类的视图源码分析 一
基于类的视图(Class-based view)是Django 1.3引入的新的视图编写方式,用于取代以前基于函数(Function-based)方式. 借助于OO和Python中方便的多重继承特性, ...
- Altium Designer 10 | 常用库及部分元件名中英文对照表
———————————————————————————————————————————— 常用库及部分元件名中英文对照表 - - - - - - - - - - - - - - - - - - - - ...
- 为 jquery validate 添加验证失败回调
转载自:https://blog.csdn.net/huang100qi/article/details/52619227 1. jquery Validation Plugin - v1.15.1 ...
- centos7安装thrift
1. 升级所有软件包 yum -y update 2.安装开发工具 yum -y groupinstall "Development Tools" 3.安装wget yum -y ...
- Android布局中match_parent和fill_parent的差别
今天在做项目的一个新功能的时候,从网上查找资源,发现android2.2中出现的MATCH_PARENT感到不明确.过去仅仅有FILL_PARENT和WRAP_CONTENT那么match_paren ...
- 联想电脑Win8升级win10后Wlan关闭无法开启解决办法
官网下载电源驱动,下载无线网上驱动 开启电脑 按fn+f5 电源管理界面就出来了 把无线网卡打开 就ok了 这样就开启了无线! 如果还不行,可进行如下尝试,希望有所帮助: 1.开机进bios(一般是按 ...
- Centos RSA 登录
创建密钥 ssh-keygen -t rsa 1.用户目录下新建.ssh/authorized_keys mkdir .ssh #创建隐藏目录 #修改文件访问权限 chmod 700 .ssh cd ...
- CentOS 6.2 安装kdbg
地址:http://pkgs.org/centos-5/centos-x86_64/kdbg-2.0.2-1.2.1.x86_64.rpm.html 百度网盘地址:http://pan.baidu.c ...