TOJ 1809.Playground(构成多边形条件)

题目链接:http://acm.tju.edu.cn/toj/showp1809.html


1809.    Playground
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 3056    Accepted Runs: 770



George has K ≤ 20 steel wires shaped in the form of half-circles, with radii a 1, a 2, ... , a K. They can be soldered (connected) at the ends, in any angle. Is it possible for George to make a closed shape out of these wires? He does not have to use all the wires.

The wires can be combined at any angle, but may not intersect. Beware of floating point errors.

Input specifications

Each data set consists of a number 0 < K ≤ 20 on a line by itself, followed by a line of K space-separated numbers ai. Each number is in the range 0 < ai < 107, and has at most 3 digits after the decimal point. The input will be terminated by a zero on a line by itself.

Output specifications

For each test case, there should be one word on a line by itself: "YES" if it is possible to make a simple connected figure out of the given arcs, and "NO" if it isn't.

Sample Input

1
4.000
2
1.000 1.000
3
1.455 2.958 4.424
7
1.230 2.577 3.411 2.968 5.301 4.398 6.777
0

Sample Output

NO
YES
NO
YES


Source: Nordic Collegiate Contest 2005
Submit   List    Runs   Forum   Statistics


与构成多边形的条件差不多,对于半圆,要注意的是两个半圆也是可以闭合的,还有就是等于也是可以的。

#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	double wire[21];
	int n;
	while(~scanf("%d",&n),n){
		bool flag=false;
		for(int i=0;i<n;i++)
			scanf("%lf",&wire[i]);
		sort(wire,wire+n);
		double sum=wire[0];
		for(int i=1;i<n;i++){
			if(wire[i]<=sum){
				flag=true;
				break;
			}
			sum+=wire[i];
		}
		if(flag)	printf("YES\n");
		else printf("NO\n");
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值