南阳06----喷水装置(一)

 1 //简单的贪心。
 2 #include <iostream>
 3 #include <cmath>
 4 #include <algorithm>
 5 using namespace std;
 6 double r[605],s;
 7 bool cmp(double x,double y)
 8 {
 9     return x > y;
10 }
11 bool add(double r)
12 {
13     if(r <= 1.0 || s <= 0)
14         return false;
15     s -= 2.0*sqrt(r*r-1.0);
16     return true;
17 }
18 int main()
19 {
20     int t,n;
21     cin >> t;
22     while(t--)
23     {
24         cin >> n;
25         for(int i=0; i<n; ++i)
26             cin >> r[i];
27         sort(r,r+n,cmp);
28         int ans = 0;
29         s = 20.0;
30         for(int i=0; i<n; ++i)
31             if(add(r[i]))
32                 ++ans;
33             else
34                 break;
35         cout << ans << endl;
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/qq188380780/p/7255996.html