灌水VS抽水
来源:互联网 发布:js自动轮播图代码 编辑:程序博客网 时间:2024/04/30 14:03
灌水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
22 32-2 32-2 -20
Sample Output
2NO 1Impossible
Author
//题意是说这有个池塘,然后有许多泵可以抽水也可以放水问是否可以填满池塘。
分三种情况,可以填满需要多长时间,不能填满最少需要关掉几个泵,不能填满。
思路:先把每个泵的速度求出来然后按从小到大排序,置标志如果速度都是小于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;}
0 0
- 灌水VS抽水
- 灌水VS抽水
- 灌水VS抽水
- 继续灌水,Windows vs Linux
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 注水抽水问题
- 破解挖矿抽水教程
- 前来灌水
- 今日灌水
- Sina 灌水
- 灌水回复
- 灌水贴
- 计算机视觉领域的一些牛人博客,研究机构等的网站链接
- iOS围绕某点缩放或旋转的AnchorPoint的设定
- 索引数组冒泡方法
- PHP中间件--ICE
- 配置Nginx前端Apache后端服务器LNMPA-与LNMP,HHVM性能比拼
- 灌水VS抽水
- Eclipse安装Marketplace Client
- JMS简介与ActiveMQ实战
- 谈下博客中如何创建Post视图
- [WebApp]定宽网页设计下,固定宽度布局开发WebApp并实现多终端下WebApp布局自适应
- rpm Header V3 DSA signature: NOKEY 错误解决
- Primefaces4.0 JSF2.0 Liferay6.1开发中设置所允许上传文件的最大字节数
- ubuntu 12.04下访问windows共享文件夹
- HTML4 和 HTML5 的10个关键区别