码迷,mamicode.com
首页 > 其他好文 > 详细

灌水VS抽水

时间:2014-07-18 18:12:47      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:acm

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

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;
}


 

灌水VS抽水,布布扣,bubuko.com

灌水VS抽水

标签:acm

原文地址:http://blog.csdn.net/u012773338/article/details/37927841

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!