CodeForces

来源:互联网 发布:淘宝代购是真货么 编辑:程序博客网 时间:2024/06/05 15:09

题目:

B. Coat of Anticubism time limit per test1 second memory limit per
test256 megabytes inputstandard input outputstandard output

As some of you know, cubism is a trend in art, where the problem of
constructing volumetrical shape on a plane with a combination of
three-dimensional geometric shapes comes to the fore.

A famous sculptor Cicasso, whose self-portrait you can contemplate,
hates cubism. He is more impressed by the idea to transmit
two-dimensional objects through three-dimensional objects by using his
magnificent sculptures. And his new project is connected with this.
Cicasso wants to make a coat for the haters of anticubism. To do this,
he wants to create a sculpture depicting a well-known geometric
primitive — convex polygon.

Cicasso prepared for this a few blanks, which are rods with integer
lengths, and now he wants to bring them together. The i-th rod is a
segment of length li.

The sculptor plans to make a convex polygon with a nonzero area, using
all rods he has as its sides. Each rod should be used as a side to its
full length. It is forbidden to cut, break or bend rods. However, two
sides may form a straight angle .

Cicasso knows that it is impossible to make a convex polygon with a
nonzero area out of the rods with the lengths which he had chosen.
Cicasso does not want to leave the unused rods, so the sculptor
decides to make another rod-blank with an integer length so that his
problem is solvable. Of course, he wants to make it as short as
possible, because the materials are expensive, and it is improper deed
to spend money for nothing.

Help sculptor!

Input The first line contains an integer n (3 ≤ n ≤ 105) — a number of
rod-blanks.

The second line contains n integers li (1 ≤ li ≤ 109) — lengths of
rods, which Cicasso already has. It is guaranteed that it is
impossible to make a polygon with n vertices and nonzero area using
the rods Cicasso already has.

Output Print the only integer z — the minimum length of the rod, so
that after adding it it can be possible to construct convex polygon
with (n + 1) vertices and nonzero area from all of the rods.

Examples input 3 1 2 1 output 1 input 5 20 4 3 2 1 output 11 Note In
the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed
from a set of lengths {1, 1, 1, 2}.

In the second example you can make a triangle with lengths
{20, 11, 4 + 3 + 2 + 1 = 10}.

思路:

这个题。。题意我看了很久,但是看懂以后,就知道这是个水题了
输入n,再输入n个数,表示有n根长度不同的木棒。
给出若干条边,要求再加上一条边,使得所有的边能构成凸多边形.求这条新加边的最小长度(保证给出的边不能构成凸多边形).

这个凸多边形,起始也就是三角形,然后就按照能否构成三角形来考虑,先把所有的木棒的长度加起来,然后你按照木棒的长度从小到大排序,减去那个最长的木棒,看看剩下的长度的总和和那个最长的木棒比较(要满足两边之和大于第三边),如果最大的那个木棍的长度不够的话,就给他正好加上1,具体看代码

代码:

#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N 111111#define M 1000000#define ll long longusing namespace std;int a[N];int main(){    int n,sum=0;    scanf("%d",&n);    for(int i=1; i<=n; i++)    {        scanf("%d",&a[i]);            sum+=a[i];    }    sort(a+1,a+n+1);    sum-=a[n];    if(sum>a[n])        puts("0");    else        printf("%d\n",a[n]-sum+1);        return 0;}
0 0
原创粉丝点击