传送门:http://codeforces.com/contest/895/problem/A

A. Pizza Separation

time limit per test1 second

memory limit per test256 megabytes

Problem Description

Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.

Input

The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.

The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.

Output

Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.

Examples

input

4

90 90 90 90

output

0

input

3

100 100 160

output

40

input

1

360

output

360

input

4

170 30 150 10

output

0

Note

In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.

In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.

In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.

Picture explaning fourth sample:

Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.


解题心得:

  1. 这场比赛真的是打蒙了,A题啊,旁边一个小子念叨了一句dp,然后就被带歪了,按着0-1背包问题来写,结果人家说的很清楚啊,必须是连续的披萨块,一个小小的坑点就是披萨是圆的,首尾相连,一个模拟很轻松的解决。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 380;
int num[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
int Min = 360;
int sum = 0;
for(int i=0;i<n;i++)
{
int t = 0;
int cnt = i;//枚举连续披萨的起点位置
sum = 0;
while(t < n)//收尾相连但是不能超过n块
{
sum += num[cnt];
if(abs(360-sum*2) < Min)
Min = abs(360-sum*2);
cnt++;
t++;
if(cnt >= n)
cnt = 0;
}
}
printf("%d",Min);
return 0;
}

CodeForces:#448 div2 a Pizza Separation的更多相关文章

  1. #448 div2 a Pizza Separation

    A. Pizza Separation time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  2. CodeForces:#448 div2 B. XK Segments

    传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...

  3. Codeforces Round #448 (Div. 2) A. Pizza Separation【前缀和/枚举/将圆(披萨)分为连续的两块使其差最小】

    A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. codeforces 895A Pizza Separation 枚举

    codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...

  5. Codeforces #448 Div2 E

    #448 Div2 E 题意 给出一个数组,有两种类型操作: 选定不相交的两个区间,分别随机挑选一个数,交换位置. 查询区间和的期望. 分析 线段树区间更新区间求和. 既然是涉及到两个区间,那么对于第 ...

  6. Codeforces 895.A Pizza Separation

    A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. 895A. Pizza Separation#分披萨问题(前缀和)

    题目出处:http://codeforces.com/problemset/problem/895/A 题目大意:对于给出的一些角度的披萨分成两份,取最小角度差 #include<stdio.h ...

  8. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  9. Codeforces Round #448(Div.2) Editorial ABC

    被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...

随机推荐

  1. 在项目中导入import javax.servlet 出错解决办法

    我们有时会把别人的项目copy到自己这里进行二次开发或者参考学习,有的时候会发生下图的错误,即eclipse项目里我们导入的项目里提示HttpServletRequest 不能引用,会伴随头疼的小红叉 ...

  2. [COGS 347]地震

    时间限制:4 s   内存限制:128 MB 问题描述 某国地形狭长,中部有一列山脉,由于多发地震,山脉在不断变化中.地震发生时,山脉有可能发生如下变化:局部海拔升高或降低,板块运动产生地裂而出现一段 ...

  3. 自定义控件使用GDI+绘制旋转Label文字

    http://www.cnblogs.com/CUIT-DX037/ 1.添加用户控件: 2.添加代码: public partial class UcLabel : UserControl { pu ...

  4. 深入剖析javaScript中的深拷贝和浅拷贝

    如何区分深拷贝与浅拷贝,简单来说,假设B复制了A,当修改A时,看B是否会发生变化,如果B也跟着变了,说明这是浅拷贝,如果B没变,那就是深拷贝:我们先看两个简单的案例: //案例1(深拷贝) var a ...

  5. Tomcat Stack-8.0.35 (OpenLogic CentOS7.2)

       平台: CentOS 类型: 虚拟机镜像 软件包: apache2.4.20 mysql5.6.30 tomcat8.0.35 apache application server basic s ...

  6. 703. 数据流中的第 K 大元素

    设计一个找到数据流中第 K 大元素的类(class).注意是排序后的第 K 大元素,不是第 K 个不同的元素. 你的 KthLargest 类需要一个同时接收整数 k 和整数数组 nums 的构造器, ...

  7. ECLIPSE 取消自动更新

    经常遇到一开eclipse 时,一直很卡的问题,发现是它一直尝试联网更新东西 ,如maven 所以解决办法  , eclipse 取消自动更新的方法: 1. window --> prefere ...

  8. mif文件生成方法

    mif文件就是存储器初始化文件,即memory initialization file,用来配置RAM或ROM中的数据.常见生成方法: Quartus自带的mif编辑器生成 mif软件生成 高级编程语 ...

  9. html5标准

    1.<!DOCTYPE html> html5标准网页声明,原先的是一串很长的字符串,现在是这个简洁形式,支持html5标准的主流浏览器都认识这个声明.表示网页采用html5 浅谈:htm ...

  10. 在IIS 7.5上安装WebDAV(http文件下载上传)

    WebDAV 简介 WebDAV (Web-based Distributed Authoring and Versioning) 一种基于 HTTP 1.1协议的通信协议.它扩展了HTTP 1.1, ...