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. gdbhooks 栈信息

    https://devguide.python.org/gdb/ https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html#Pytho ...

  2. Ubuntu配置国内高速apt-get更新源

    Ubuntu配置国内高速apt-get更新源     具体内容直接参考这篇博客:https://www.linuxidc.com/Linux/2017-11/148627.htm 此网站可直接找到符合 ...

  3. CDH 部署 Hadoop:5.开始安装

    Cloudera Enterprise 6.2.x   或者参考https://blog.csdn.net/shawnhu007/article/details/52579204 第零步:优化相关 e ...

  4. python脚本使用源码安装不同版本的python

    # coding=utf-8 import os import sys # 判断是否是root用户 if os.getuid() == 0: pass else: print('当前用户不是root用 ...

  5. 二、HTTP请求

    一.测试对象:v2ex的api 文档:https:www.v2ex.com/p/7vpTEc53 api:https://www.v2ex.com/api/topic/hot.json 最热主题:相当 ...

  6. 全面系统Python3入门+进阶-1-3 我为什么喜欢Python

    结束

  7. C++笔试

    个人整理,借鉴网络 1.C和C++中struct的区别 1).C的struct无protect和private属性,C++的有 2).C不能定义函数,C++能 3).C中struct加了typedef ...

  8. python初级 1 内存和变量

    一.回顾: 1.什么是程序 一堆指令的集合 2.回想一下猜数游戏程序的特征: 1)需要输入(input) 2)会处理输入(process) 3)产生输出(output) 二.程序的一般特征:输入.处理 ...

  9. 面向对象(实际就像python跳用自己写的库那样)

    被调用的对象(库) FanFa.java 文件 package com.BM; public class FanFa { #变量值 int r=4 #方法 public static void uui ...

  10. clientHeight,offsetHeight,scrollHeight迷一样的三个值

    https://blog.csdn.net/qq_39083004/article/details/78498178 https://www.imooc.com/article/17571  推荐 o ...