灌水VS抽水
来源:互联网 发布:cnabs数据库全称 编辑:程序博客网 时间:2024/04/30 11:53
Problem DescriptionThere 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.InputThere 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.OutputIf 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 Input22 32-2 32-2 -20Sample Output2NO 1Impossible//标程:#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;double a[100];const double inf = 1e-8;int main(){//freopen("a.txt","r",stdin);//freopen("b.txt","w",stdout); int n, i;while(cin >> n){if(n == 0) break;double sum = 0.0;for(i = 0; i < n; ++ i){double x;cin >> x;a[i] = 1.0 / x;sum += a[i];}sort(a,a+n); if(sum > inf){sum = 1.0 / sum;int tmp = (int)sum;if(sum - tmp > inf) tmp ++;cout << tmp << endl;}else{for(i = 0; i < n; ++ i){sum -= a[i];if(sum > inf) break;}if(i == n) cout << "Impossible" << endl;else cout << "NO " << i + 1 << endl;}}return 0;}
0 0
- 灌水VS抽水
- 灌水VS抽水
- 灌水VS抽水
- 继续灌水,Windows vs Linux
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 灌水
- 注水抽水问题
- 破解挖矿抽水教程
- 前来灌水
- 今日灌水
- Sina 灌水
- 灌水回复
- 灌水贴
- StuanGou
- Uva-1625-Color Length
- 文章标题title优化技巧
- 如何在centos安装python-mysql?
- APUE第三章 文件I/O
- 灌水VS抽水
- 第十章 BIRT图表(续) .
- Android convertToBytes StringIndexOutOfBoundsException 调试小结
- jQuery扩展开发
- qemu及Guest OS环境搭建
- json数据基础处理
- 题目1516:调整数组顺序使奇数位于偶数前面
- Android中OnScrollListener回调具体剖析
- Git常用操作命令收集