灌水VS抽水
来源:互联网 发布:数据库导入excel 编辑:程序博客网 时间:2024/04/30 14:05
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
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<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;#define INF 1.e-8int pump[205],n;double pump1[205];int main(){//freopen("b.txt","r",stdin);while(scanf("%d",&n)==1&&n){int i,flag=0;double sum=0.0;for(i=1;i<=n;i++){scanf("%d",&pump[i]);if(pump[i]>0) flag=1;pump1[i]=1.0/(pump[i]*1.0);sum+=pump1[i];}sort(pump1+1,pump1+n+1);if(!flag)printf("Impossible\n");else{if(sum>INF){double tmp=1.0/sum;int x=(int)tmp;if(tmp-x>INF)printf("%d\n",x+1);else printf("%d\n",x);}else {for(i=1;i<=n;i++){sum-=pump1[i];if(sum>INF) break;}printf("NO %d\n",i);}}}return 0;}
0 0
- 灌水VS抽水
- 灌水VS抽水
- 灌水VS抽水
- 继续灌水,Windows vs Linux
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 注水抽水问题
- 破解挖矿抽水教程
- 前来灌水
- 今日灌水
- Sina 灌水
- 灌水回复
- 灌水贴
- UVA 437 The Tower of Babylon
- 刘鹏计算广告学1:广告的基本知识(一)
- iOS 远程推送(Push Notification)实现
- VC++学习心得(六)
- Foundation框架
- 灌水VS抽水
- 巧用U盘来蹭网的技巧
- 内存管理的艺术
- hbase基本操作
- 逻辑回归
- Linux基本命令一
- 深搜 WA
- 基于CRF的中文分词
- UVA10177 (2/3/4)-D Sqr/Rects/Cubes/Boxes?