首页 > 代码库 > 灌水VS抽水
灌水VS抽水
灌水VS抽水
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 25 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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.
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
Author
HYNU
//题意是说这有个池塘,然后有许多泵可以抽水也可以放水问是否可以填满池塘。
分三种情况,可以填满需要多长时间,不能填满最少需要关掉几个泵,不能填满。
思路:先把每个泵的速度求出来然后按从小到大排序,置标志如果速度都是小于0 直接输出imposs,如果速度和大于0 则计算填满需要多长时间,否则则计算需要关闭几个duo
#include<cstdio> #include<algorithm> using namespace std; #define INF 1.e-8 //控制精度 int main() { //freopen("a.txt","r",stdin); //freopen("b.txt","w",stdout); int n,a,i,flag; double s,f[205]; int ss; while(scanf("%d",&n)!=EOF&&n) { s=0.0; flag=0; for(i=1;i<=n;i++) { scanf("%d",&a); f[i]=1.0/a; //速度 s+=f[i]; //速度和 if(f[i]>0) flag=1; //标志位 } sort(f+1,f+n+1);//从小到大排序 if(flag==0) printf("Impossible\n"); else { if(s>INF) //是正数 { s=1.0/s; ss=(int)s; if(s-ss>INF) ss++; //向上取整 printf("%d\n",ss); } else { for(i=1;i<=n;i++) { s-=f[i]; if(s>INF) break; } printf("NO %d\n",i); //需要关掉几个 duo } } } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。