传送门: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. SpringBoot | 第二十六章:邮件发送

    前言 讲解了日志相关的知识点后.今天来点相对简单的,一般上,我们在开发一些注册功能.发送验证码或者订单服务时,都会通过短信或者邮件的方式通知消费者,注册或者订单的相关信息.而且基本上邮件的内容都是模版 ...

  2. hibernate课程 初探单表映射3-1 hibernate单表操作简介

    本章简介: 1 单一主键 2 基本类型 3 对象类型 4 组件属性 5 单表操作CRUD实例

  3. 构建第一个spring boot2.0应用之项目启动运行的几种方式(二)

    方法一. 配置Run/Debug Configuration  选择Main Class为项目 Application启动类(入口main方法) (2).进行项目目录,即包含pom.xml的目录下,启 ...

  4. Java static修饰符小记

    首先我们明确一点:java是一个纯面向对象的编程语言,它的每一个文件都视为一个类,当我们创建一个对象的时候,就是在调用一个文件,那么这个时候,这个文件(类)里的一些东西,它是需要通过对象来使用或访问, ...

  5. 使用后台程序的第一个程序hello word

    1.在advanced\backend\SiteController.php中输入 2.在advanced\backend\Views文件夹下添加名字为say.php的文件,文件名必须和控制器中的视图 ...

  6. [Asp.Net] MVC 和Web API Action 获取参数的区别

    Asp.net MVC 和web api 的action 在获取从前台传入的数据是有很大不同 前台使用ajax的方式向后台发起post的请求 Content-Type:application/json ...

  7. 部署git服务器(Windows Server 2008)

    原来的这个项目是一个人开发的,没有做版本管理,我接手后准备搭建git版本管理服务端,方便离线开发和做版本管理: 一台云主机,操作系统:Windows Server 2008,64位: java已经安装 ...

  8. flash + php对称密钥加密的交互

    这几天研究了下php和flash中的对称密钥加密的交互问题,经过研究以后决定,在项目中使用aes加密.问题也就来了,在flash中的加密数据如何与php的amf进行数据交互,最终决定使用base64编 ...

  9. 2018.7.1 css项目之模仿满屋花首页css+idv布局实现

    可以分开写 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF ...

  10. js数据结构处理--------扁平化数组处理为树结构数据

    将扁平化的数组处理为树结构数据,我们可以利用对象来处理,对象的复制是浅拷贝,指向相同的内存地址: var arr = [ { id: 0, pid: -1, name: 'sadas' }, { id ...