#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 ;
}
#448 div2 a Pizza Separation的更多相关文章
- CodeForces:#448 div2 a Pizza Separation
传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...
- 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 ...
- codeforces 895A Pizza Separation 枚举
codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...
- Codeforces #448 Div2 E
#448 Div2 E 题意 给出一个数组,有两种类型操作: 选定不相交的两个区间,分别随机挑选一个数,交换位置. 查询区间和的期望. 分析 线段树区间更新区间求和. 既然是涉及到两个区间,那么对于第 ...
- Codeforces 895.A Pizza Separation
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 895A. Pizza Separation#分披萨问题(前缀和)
题目出处:http://codeforces.com/problemset/problem/895/A 题目大意:对于给出的一些角度的披萨分成两份,取最小角度差 #include<stdio.h ...
- CodeForces:#448 div2 B. XK Segments
传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...
- Codeforces Round #448(Div.2) Editorial ABC
被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...
- CF泛做
CF Rd478 Div2 A Aramic script 题意:给定几个字符串,去重后,求种类 思路:直接map乱搞 #include<bits/stdc++.h> using name ...
随机推荐
- 判断x的m次方和y的m次方末尾三位数是否相等
/*==============================================对于任意给定的两个正整数x和y,是否存在一个不超过100的正整数m使得x^m与y^m的末尾三位数相等呢? ...
- Kubernetes addons 之 coredns部署
Kubernetes addons 之 coredns部署 2019.06.04 18:04:35字数 1045阅读 121 DNS 是 Kubernetes 的核心功能之一,通过 kube-dns ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_17、SpringBootTest单元测试实战
笔记 1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程 ...
- flutter 中的搜索条实现
import 'package:flutter/material.dart'; import 'package:flutter_app/SearchBarDemo.dart'; void main() ...
- Xadmin权限管理
需求分析: 1.判断用户是否登陆,未登陆就不能进入其他页面2.为用户分配不同的权限,用户的操作只能在权限范围之内3.将用户可操作的权限显示在页面山,点击能进入该页面操作 模型表的建立 1.对每个用户建 ...
- canvas固定画布
canvas作为非常方便的HTML绘图工具在web端的应用是非常多了. 那么会碰到一个问题,开始绘图的时候,网页总是晃动. 怎么办呢?只需在获取鼠标(触点)移动坐标的时候,添加清除默认动作就可以了. ...
- jenkins下载插件Git Parameter插件
登陆jekinse -> 点击左边菜单列表 -> 点”系统管理“ -> 下拉点”插件管理“ -> 选“可选插件”,在右上角过滤框输入”Git Parameter” -> ...
- k8s记录-ca证书制作(二)
1)下载cfssl #!/bin/bash wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 wget https://pkg.cfssl.org/R ...
- CentOS7下搭建Redis主从复制
(1).实验环境 youxi1 192.168.1.6 Master服务器 youxi2 192.168.1.7 Slave服务器 (2).实验 1)两台服务器上yum安装Redis,启动并设置开机自 ...
- Shell中 2>/dev/null
1.文件描述符 Linux系统预留可三个文件描述符:0.1和2,他们的意义如下所示: 0——标准输入(stdin) 1——标准输出(stdout) 2——标准错误(stderr) 标准输出——stdo ...