标签:sicily
Time Limit: 1 secs, Memory Limit: 32 MB
George has K <= 20 steel wires shaped in the form of half-circles, with radii a1, a2, . . . , aK. 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.
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.
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.
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
NO YES NO YES
#include <stdio.h> #include <algorithm> using namespace std; //其实可以把圆看成一条线段,这条线段的长度等于圆的半径的两倍 //每次都从中找出最长的一条边,并把其他边的和算出来,假如和比最长边小,说明这条最长边是肯定不行了,扔掉,然后重复 int main() { bool is_ok; int n, i, j; double sum, max, a[21]; while (scanf("%d", &n) && n) { for (i = 0, max = 0, sum = 0, is_ok = false; i < n; i++) { scanf("%lf", &a[i]); } sort(a, a + n); for (i = n - 1; i >= 0; i--) { max = a[i]; for (j = 0, sum = 0; j < i; j++) { sum += a[j]; } if (sum >= max) { is_ok = true; break; } } if (is_ok) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
标签:sicily
原文地址:http://blog.csdn.net/u012925008/article/details/44738717