南阳OJ-6-喷水装置(一)

题目链接:

http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=6

题目大意:

现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0<Ri<15)的圆被湿润,这有充足的喷水装置i(1<i<600)个,并且一定能把草坪全部湿润,你要做的是:选择尽量少的喷水装置,把整个草坪的全部湿润。

思路:

一开始以为是区间问题,后面发现每个喷水装置没有固定的点,只考虑覆盖长度即可,所以瞬间简化成n个数取出前x个使得其大于20即可。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 const int maxn = 1e6 + 10;
 8 int T, n;
 9 double a[700];
10 int main()
11 {
12     cin >> T;
13     while(T--)
14     {
15         cin >> n;
16         double x;
17         int tot = 0;
18         for(int i = 0; i < n; i++)
19         {
20             cin >> x;
21             if(x <= 1)continue;
22             a[tot++] = 2.0 * sqrt(x * x - 1);
23         }
24         sort(a, a + tot);
25         int ans = 0;
26         double sum = 0.0;
27         for(int i = tot - 1; i >= 0; i--)
28         {
29             sum += a[i];
30             ans++;
31             if(sum >= 20)break;
32         }
33         cout<<ans<<endl;
34     }
35     return 0;
36 }

 传送门:喷水装置(二)

posted @ 2018-03-31 19:19  _努力努力再努力x  阅读(206)  评论(0编辑  收藏  举报