A. Pizza Separation 
time limit per test1 second 
memory limit per test256 megabytes 
inputstandard input 
outputstandard output 
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 

90 90 90 90 
output 

input 

100 100 160 
output 
40 
input 

360 
output 
360 
input 

170 30 150 10 
output 

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.

题解:写的时候没注意到是取连续的区间,喵的老了。暴力枚举区间就可以了 复杂度360*360

代码:

#include <iostream>
#include <math.h>
using namespace std; int main(){
int ans=;
int sector[];//扇形数组
int numberOfSector;//扇形个数
cin>>numberOfSector;
for(int i=;i<numberOfSector;i++){
cin>>sector[i];
}
for(int i=;i<numberOfSector;i++){
int temp=;//临时存放当前扇形度数和
for(int j=;j<numberOfSector;j++){
temp+=sector[(i+j)%numberOfSector];//关键步骤
ans=min(ans,abs(-temp));
}
}
cout<<ans*<<endl; return ;
}

最新文章

  1. 办公OA的登陆界面..
  2. 万能的林萧说:我来告诉你,一个草根程序员如何进入BAT。
  3. 一篇说尽Excel常见函数用法
  4. objective-c-sort-keys-of-nsdictionary-based-on-dictionary-entries
  5. OpenJDK和OracleJDK的JVM性能有多大差距
  6. Java IO (5) - 总结
  7. 简单高效读写修改整个文本Slurp
  8. js右侧悬浮框
  9. shell-3
  10. [bzoj4864][BeiJing 2017 Wc]神秘物质
  11. 异步 JavaScript 之 macrotask、microtask
  12. Option path is not valid. Please refer to the README.
  13. 实验三:分别用for,while;do-while循坏语句以及递归的方法计算n!,并输出算式。
  14. 2019年DNS服务器速度排行榜
  15. 2017-12-15python全栈9期第二天第七节之数字转换成布尔值
  16. 51Nod 1299 监狱逃离
  17. loj#2071. 「JSOI2016」最佳团体
  18. Java 分布式和集中式理解
  19. Android之RadioButton多行
  20. 【tomcat】servlet原理及其生命周期

热门文章

  1. https://docs.huihoo.com/infoq/qconbeijing/2016/day1/工程效率提升专题/2-2-支持百度万人开发的工具装备及百度工程能力建设-夏仲璞.pdf
  2. Windows安装Redis并添加本地自启动服务并解决客户端dll报错
  3. Oracle列信息表 all_tab_columns中的data_length和data_precision字段区别
  4. 使用Dapper.Contrib
  5. 算力和AI-ZILLIZ
  6. 005-guava 集合-集合工具类-java.util.Collections中未包含的集合工具[Maps,Lists,Sets],Iterables、Multisets、Multimaps、Tables
  7. 002-guava String 操作
  8. 003-结构型-02-装饰模式(Decorator)
  9. DataWorks2.0——DataStudio简单对比使用上手
  10. 深入学习c++--lambda函数