Pizza Separation——————数学

题意翻译

学生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.

输入输出样例

输入样例#1: 复制
4
90 90 90 90
输出样例#1: 复制
0

输入样例#2: 复制
3
100 100 160
输出样例#2: 复制
40

输入样例#3: 复制
1
360
输出样例#3: 复制
360

输入样例#4: 复制
4
170 30 150 10
输出样例#4: 复制
0

说明

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 3600=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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值