Problem Description
There is something crazy! There is a pool and many of pumps to fill up the empty pool. We know that the capacity of each pump. And at last,
we want you to tell us whether we can fill up the empty pool and the time we have to. And if we can’t fill up the pool with all of the pumps,
the least number of pumps we have to close.
Input
There are multiply test cases in this problem. In each test case, first line is a integer of n(1<=n<=15), which is the number of pumps.
At the second line there are n integers ai(1<=|ai|<=10),which is the time(in hours) to fill up the empty pool(ai>0) or to empty the pool(ai<0).
All the cases will be end with n=0.
Output
If we can fill up the empty pool with all of the pump, print the hours (in integer) we have to use, otherwise print one line of “NO” and
the least number we have to close up. At last, if we can’t fill up the pool with some of the pumps closed, print one line of “Impossible”.
Sample Input
2
2 3
2
-2 3
2
-2 -2
0
Sample Output
2
NO 1
Impossible
//标程:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
double a[100];
const double inf = 1e-8;
int main()
{
// freopen("a.txt","r",stdin);
// freopen("b.txt","w",stdout);
int n, i;
while(cin >> n)
{
if(n == 0) break;
double sum = 0.0;
for(i = 0; i < n; ++ i)
{
double x;
cin >> x;
a[i] = 1.0 / x;
sum += a[i];
}
sort(a,a+n);
if(sum > inf)
{
sum = 1.0 / sum;
int tmp = (int)sum;
if(sum - tmp > inf) tmp ++;
cout << tmp << endl;
}
else
{
for(i = 0; i < n; ++ i)
{
sum -= a[i];
if(sum > inf) break;
}
if(i == n) cout << "Impossible" << endl;
else cout << "NO " << i + 1 << endl;
}
}
return 0;
}
灌水VS抽水
最新推荐文章于 2020-02-02 11:55:04 发布