#448 div2 a Pizza Separation
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
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.
题解:写的时候没注意到是取连续的区间,喵的老了。暴力枚举区间就可以了 复杂度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 ;
}
最新文章
- 办公OA的登陆界面..
- 万能的林萧说:我来告诉你,一个草根程序员如何进入BAT。
- 一篇说尽Excel常见函数用法
- objective-c-sort-keys-of-nsdictionary-based-on-dictionary-entries
- OpenJDK和OracleJDK的JVM性能有多大差距
- Java IO (5) - 总结
- 简单高效读写修改整个文本Slurp
- js右侧悬浮框
- shell-3
- [bzoj4864][BeiJing 2017 Wc]神秘物质
- 异步 JavaScript 之 macrotask、microtask
- Option path is not valid. Please refer to the README.
- 实验三:分别用for,while;do-while循坏语句以及递归的方法计算n!,并输出算式。
- 2019年DNS服务器速度排行榜
- 2017-12-15python全栈9期第二天第七节之数字转换成布尔值
- 51Nod 1299 监狱逃离
- loj#2071. 「JSOI2016」最佳团体
- Java 分布式和集中式理解
- Android之RadioButton多行
- 【tomcat】servlet原理及其生命周期
热门文章
- https://docs.huihoo.com/infoq/qconbeijing/2016/day1/工程效率提升专题/2-2-支持百度万人开发的工具装备及百度工程能力建设-夏仲璞.pdf
- Windows安装Redis并添加本地自启动服务并解决客户端dll报错
- Oracle列信息表 all_tab_columns中的data_length和data_precision字段区别
- 使用Dapper.Contrib
- 算力和AI-ZILLIZ
- 005-guava 集合-集合工具类-java.util.Collections中未包含的集合工具[Maps,Lists,Sets],Iterables、Multisets、Multimaps、Tables
- 002-guava String 操作
- 003-结构型-02-装饰模式(Decorator)
- DataWorks2.0——DataStudio简单对比使用上手
- 深入学习c++--lambda函数