CodeForces:#448 div2 a Pizza Separation
传送门:http://codeforces.com/contest/895/problem/A
A. Pizza Separation
time limit per test1 second
memory limit per test256 megabytes
Problem Description
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.
解题心得:
- 这场比赛真的是打蒙了,A题啊,旁边一个小子念叨了一句dp,然后就被带歪了,按着0-1背包问题来写,结果人家说的很清楚啊,必须是连续的披萨块,一个小小的坑点就是披萨是圆的,首尾相连,一个模拟很轻松的解决。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 380;
int num[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
int Min = 360;
int sum = 0;
for(int i=0;i<n;i++)
{
int t = 0;
int cnt = i;//枚举连续披萨的起点位置
sum = 0;
while(t < n)//收尾相连但是不能超过n块
{
sum += num[cnt];
if(abs(360-sum*2) < Min)
Min = abs(360-sum*2);
cnt++;
t++;
if(cnt >= n)
cnt = 0;
}
}
printf("%d",Min);
return 0;
}
CodeForces:#448 div2 a Pizza Separation的更多相关文章
- #448 div2 a Pizza Separation
A. Pizza Separation time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- 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) 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 Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #448(Div.2) Editorial ABC
被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...
随机推荐
- 关于docker下容器和宿主机器时间不一致问题
在前几天,在阿里云的ECS上部署一个docker应用时,发现部署的应用在请求第三方应用时,一直出现超时的异常提示,刚开始以为是第三方应用系统的问题(此系统无赖躺枪,反正也不是一次两次了,多躺几次也就习 ...
- SQLServer 索引的使用情况
—在优化查询SQL语句,查看索引使用情况SQL语句: select db_name(database_id) as N'数据库名称', object_name(a.object_id) as N'表名 ...
- C#---vs2010发布、打包安装程序程序(转载)
转载地址:点击打开 1. 在vs2010 选择“新建项目”→“ 其他项目类型”→“ Visual Studio Installer→“安装项目”: 命名为:Setup1 . 这是在VS2010中将有三 ...
- uvm_hdl——DPI在UVM中的实现(四)
我们可以在uvm中实现HDL的后门访问,具体包括的function有uvm_hdl_check_path,uvm_hdl_deposit, uvm_hdl_force,uvm_hdl_release, ...
- 关于HTML中时间格式以及查询数据库的问题
1.默认时间格式,加入属性dateFormate="yyyy-MM-dd" 2.设置默认值,value="2017-6-22" 3.在JavaScript中将获 ...
- tomcat jdk官网下载教程
Tomcat不同版本官网下载: 1.官网地址:http://tomcat.apache.org/ 2.点击要下载的版本进入下载页,点击Archives进入版本选择页,然后选择对应的版本文件夹,进去后点 ...
- python 之开发工具 sublimetext 3
一.前言 由于个人工作内容太过于繁杂,记忆力又不好,为日后使用的方便,故简单的记录了本篇关于sublimetext 3的初始化安装和部分插件内容的记录.目前最新的版本也是3.0以上版本了,故我这里使用 ...
- python资料汇总
http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.html
- 动态规划专题(三)——数位DP
前言 数位\(DP\) 真的是最恶心的\(DP\). 简介 看到那种给你两个数,让你求这两个数之间符合条件的数的个数,且这两个数非常大,这样的题目一般就是 数位\(DP\) 题. 数位\(DP\)一般 ...
- Mybatis-延迟加载和缓存
延迟加载 概念: 就是在需要用到数据时才进行加载,不需要用到数据时就不加载数据.延迟加载也称懒加载. 好处:先从单表查询,需要时再从关联表去关联查询,大大提高数据库性能,因为查询单表要比关联查询多张表 ...