CodeForces 667B Coat of Anticubism(构造三角形)
2016-08-11 10:42
330 查看
http://codeforces.com/problemset/problem/667/B
B. Coat of Anticubism
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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
output
input
output
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}.
题意:
给定一些木棍的长度,要求组成一个三角形,问需要添加的最短的木棍需要多长。
思路:
按照有关三角形的定理:两边的和大于第三边。
找出给定长度中最长的木棍 max ,统计长度总和 sumlength ;
需要的最短木棍就满足
ans = max - (sumlength - max ) + 1。
Code:
#include<stdio.h>
const int MYDD=1e5+1103;
int main() {
int n;
while(scanf("%d",&n)!=EOF) {
int len;
int max=-1;//记录最长的木棒
int sumlength=0;//记录木棒总和
for(int j=0; j<n; j++) {
scanf("%d",&len);
sumlength+=len;
if(len>max) max=len;
}
int ans=max-(sumlength-max)+1;
printf("%d\n",ans);
}
return 0;
}
B. Coat of Anticubism
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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}.
题意:
给定一些木棍的长度,要求组成一个三角形,问需要添加的最短的木棍需要多长。
思路:
按照有关三角形的定理:两边的和大于第三边。
找出给定长度中最长的木棍 max ,统计长度总和 sumlength ;
需要的最短木棍就满足
ans = max - (sumlength - max ) + 1。
Code:
#include<stdio.h>
const int MYDD=1e5+1103;
int main() {
int n;
while(scanf("%d",&n)!=EOF) {
int len;
int max=-1;//记录最长的木棒
int sumlength=0;//记录木棒总和
for(int j=0; j<n; j++) {
scanf("%d",&len);
sumlength+=len;
if(len>max) max=len;
}
int ans=max-(sumlength-max)+1;
printf("%d\n",ans);
}
return 0;
}
相关文章推荐
- codeforces 487 C Prefix Product Sequence 构造+逆元
- codeforces 225B B. Well-known Numbers(数论+二分+贪心+构造)
- 第五周项目(1)-构造三角形类(5)
- Codeforces 612E - Square Root of Permutation (置换+构造)
- Codeforces 362D Fools and Foolproof Roads 构造题
- CodeForces 185A. Plant(矩阵快速幂) 构造
- CodeForces 673D - Bear and Two Paths(构造)
- 【Codeforces 141 B Hopscotch 】+ 构造
- Codeforces 804E The same permutation(构造)
- CodeForces - 848A From Y to Y(构造)
- Codeforces 453C Little Pony and Summer Sun Celebration(构造)
- CodeForces 584C - Marina and Vasya(构造)
- codeforces 487C C. Prefix Product Sequence(构造+数论)
- CodeForces-710C Magic Odd Square(幻方问题/构造)
- Codeforces 483C Diverse Permutation【思维构造】
- [Codeforces - Gym10081D (NEERC)] Distribution in Metagonia (构造+数的拆分)
- 【构造】 Codeforces 468A 24 Game
- Codeforces 550D Regular Bridge (构造)
- Codeforces 550D. Regular Bridge 构造
- 【Codeforces 756 D. Artsem and Saunders】+ 思维 + 构造