灌水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

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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 高中生晚上偷着跑出去玩怎么办 货车高速忘记过安全检查站了怎么办 u盘上的文件名称乱码了怎么办 暖气管掉进去一点水泥渣怎么办 暗埋在瓷砖下的暖气管漏水怎么办 埋在瓷砖下面的水管漏水怎么办 埋在瓷砖下的水管漏水怎么办 水压太大把水管撑坏了怎么办 无效安装包与系统不兼容怎么办 圣空法师持五戒范戒了怎么办 美航空要是不改中国台湾标志怎么办 淘宝买的东西质量有问题怎么办 天猫618长达20天c店怎么办 新开的淘宝店铺没有生意怎么办 淘宝账号登陆限制用不了花呗怎么办 闲鱼买家签收后说是空盒怎么办 在咸鱼卖东西买家恶意退货怎么办 淘宝联系不上买家物流返回怎么办 换了支付宝绑定手机号退款怎么办啊 淘宝评价错了追评评价错了怎么办 淘宝给客户退款后还给差评怎么办 淘宝账号处于下单保护状态怎么办 淘宝卖家物流单号写错了怎么办 有个人给我发直播消息怎么办 网贷申请多了现在秒拒怎么办 顺丰快递寄的瓜果坏了怎么办 淘宝退货快递公司填错了怎么办 不小心把淘宝账号注销了怎么办 腾讯视频会员开通一个月贵怎么办 微交易买美国指数输了四千块怎么办 淘宝地址中包含了违禁词怎么办 微信支付失败但是钱扣了怎么办 支付宝向别人收款交易关闭了怎么办 从淘宝充的晋江币充值异常怎么办 接手转让店铺会员要求退卡怎么办 转转买手机卖家拒绝退款怎么办 淘宝买的东西电话号码留错了怎么办 平板电脑没电关机没保存文件怎么办 恢复出厂设置需要谷歌账号怎么办 华为手机云端里照片删除了怎么办 客户退货卖家一直没收到货怎么办