题意翻译
学生Vasya和Petya在比特州立大学就读。在某一个课间他们打算订一个披萨。在这道题目中披萨是有着某个半径长度的标准圆。披萨已经被切成了 n 块,第 i 块的圆心角大小为 ai。Vasya和Petya想把整个披萨沿着切割线分成连续的两块,并且保证两人分到的披萨圆心角之差最小。注意:被分成的两块披萨中可以有一块圆心角为0。
输入格式:
输入数据的第一行包括一个整数 n( 1 <= n <= 360 ),表示披萨被分成的块数。
第二行包括 n 个整数 ai( 1 <= ai <= 360 ),表示第 i 片披萨的圆心角度数。数据保证所有圆心角度数之和为360度。
输出格式:
输出一个整数表示最小的圆心角之差。
说明:
在样例一中Vasya可以拿走第1片和第2片,Petya可以拿走第3片和第4片,那么答案即为[(90 + 90) - (90 + 90)] = 0。
在样例二中Vasya可以拿走第1片和第2片,Petya可以拿走第3片,那么答案即为[(100 + 100) - 160] = 40。
在样例三中一共只有一片披萨,它只能被一个人拿走,因此答案为(360 - 0) = 360。
在样例四中Vasya可以拿走第1片和第4片,Petya可以拿走第2片和第3片,那么答案即为[(170 + 10) - (30 + 150)] = 0。
Translated by @radish布団
题目描述
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 n n pieces. The i i i -th piece is a sector of angle equal to ai a_{i} 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.
输入输出格式
输入格式:The first line contains one integer n n n ( 1<=n<=360 1<=n<=360 1<=n<=360 ) — the number of pieces into which the delivered pizza was cut.
The second line contains n n n integers ai a_{i} ai ( 1<=ai<=360 1<=a_{i}<=360 1<=ai<=360 ) — the angles of the sectors into which the pizza was cut. The sum of all ai a_{i} ai is 360.
输出格式:Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
输入输出样例
说明
In first sample Vasya can take 1 1 1 and 2 2 2 pieces, Petya can take 3 3 3 and 4 4 4 pieces. Then the answer is ∣(90+90)−(90+90)∣=0 |(90+90)-(90+90)|=0 ∣(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 |360-0|=360 ∣360−0∣=360 .
In fourth sample Vasya can take 1 1 1 and 4 4 4 pieces, then Petya will take 2 2 2 and 3 3 3 pieces. So the answer is ∣(170+10)−(30+150)∣=0 |(170+10)-(30+150)|=0 ∣(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.
连成环的数字,将其分成两部分,求二者的最小差值
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2000;
int a[MAXN];
int b[MAXN];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
b[i]=b[i+n]=a[i];
}
int ans=0x3f3f3f3f;
for(int i=0;i<n;i++)
{
int res=0;
for(int j=i;j<n*2;j++)
{
res+=b[j];
if(res>=180)
{
break;
}
}
ans=min(res,ans);
}
printf("%d\n",abs(360-ans*2));
return 0;
}