Codeforces Round #448 (Div. 2) 895A. Pizza Separation

来源:互联网 发布:单片机读写u盘模块 编辑:程序博客网 时间:2024/05/21 12:48

题意:一个圆性披萨被分成了n块,下面n个数表示第i块的圆心角。现在要将披萨分成两个连续的扇形区域,问这两个扇形的圆心角之差最小为多少?

思路:披萨为圆形!注意连续!因为n<=360很小,所以直接枚举一个扇形区域左右端点L,R就可以。

#include<bits/stdc++.h>using namespace std;const int MAXN = 1e5 + 5;int main(){int n,a[400];while(~scanf("%d",&n)){ a[0] = 0;for(int i = 1; i <= n; i++){scanf("%d",&a[i]);a[i] = a[i] + a[i - 1]; //前缀和}int MIN = 1000;for(int i = 1; i <= n; i++){for(int j = i; j <= n; j++){MIN = min(MIN,abs(180 - (a[j] - a[i - 1])));}}printf("%d\n",2 * MIN);}return 0;}


原创粉丝点击