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 ;
}

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

  1. CodeForces:#448 div2 a Pizza Separation

    传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...

  2. 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 ...

  3. codeforces 895A Pizza Separation 枚举

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

  4. Codeforces #448 Div2 E

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

  5. Codeforces 895.A Pizza Separation

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

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

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

  7. CodeForces:#448 div2 B. XK Segments

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

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

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

  9. CF泛做

    CF Rd478 Div2 A Aramic script 题意:给定几个字符串,去重后,求种类 思路:直接map乱搞 #include<bits/stdc++.h> using name ...

随机推荐

  1. ISO/IEC 9899:2011 条款6.8.2——标签语句

    6.8.2 复合语句 语法 1.compound-statement: {    block-item-listopt    } block-item-list: block-item block-i ...

  2. Access 字段拼接(UPDATE 数据追加)

    今天遇到一个需求,在Access数据库中,有个net_id 字段,它的值是由 “jjgrape” 这个字符串和 id 字段组成的,也就是说,要把 ‘jjgrape’ 和 id 字段拼接起来: 那怎么拼 ...

  3. OpenBLAS编译 Release x64 Win10 vs2015

    >------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Build System > CMake does ...

  4. log4j 异常时在日志文件里面显示空的。

    如下图所示,输入的时候不要写 e.getStackTrace() 一般情况下不会出问题,但有时候就会出问题 解决方案

  5. 算法习题---5-5复合词(UVa10391)

    一:题目 输入一系列由小写字母组成的单词.输入已按照字典序排序,且不超过120000个.找出所有的复合词,即恰好由两个单词连接而成的单词 (一)样例输入 a alien born less lien ...

  6. 算法习题---5-3卡牌游戏(UVa10935)

    一:题目 给定n张卡片,按照1-n的顺序编号,然后拿出一张卡片扔掉,拿出一张卡片放到最后,重复该操作直到只剩1张卡片. 求扔掉的卡片序列和最后剩的卡片的编号. (一)样例输入 7 //卡牌编号从1到7 ...

  7. if判断用法

  8. Top 10 Machine Learning Algorithms For Beginners

    Linear Regression Logistic regression KNN Classification Support Vector Machine (SVM) Decision Trees ...

  9. 【Leetcode_easy】937. Reorder Log Files

    problem 937. Reorder Log Files solution: class Solution { public: vector<string> reorderLogFil ...

  10. 小程序 支持html富文本吗

    详见: https://www.jianshu.com/p/9b9b97b17393