POJ2976-Dropping tests
来源:互联网 发布:2016年双十一数据 编辑:程序博客网 时间:2024/05/29 19:38
http://poj.org/showmessage?message_id=53194
在while条件判断时要注意类似1 0的测试样例。
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const int maxn = 1000+5;const int inf = 10e9;int a[maxn];int b[maxn];double y[maxn];bool judge(double x, int n, int k) { for (int i = 0; i < n; i++) { y[i] = a[i] - b[i] * x; } sort(y, y + n); double sum = 0; for (int i = k; i < n; i++) { sum += y[i]; } return sum >= 0;}int main(int argc, char const *argv[]) { int n, k; while (scanf("%d%d", &n, &k) == 2 && (n || k)) { for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); } double lb = 0; double ub = 1; for (int i = 0; i < 100; i++) { double mid = (lb + ub) / 2; if (judge(mid, n, k)) lb = mid; else ub = mid; } printf("%d\n", (int)(lb * 100 + 0.5)); } return 0;}
0 0
- [二分]poj2976 Dropping tests
- POJ2976--Dropping tests
- POJ2976-Dropping tests
- poj2976 Dropping tests 二分
- [POJ2976] Dropping tests
- POJ2976-Dropping tests
- POJ2976:Dropping tests(二分法)
- POJ2976 Dropping tests 二分搜索
- POJ2976 Dropping tests (分数规划)
- POJ2976-Dropping tests-最大化平均值
- ZOJ3068 POJ2976 Dropping tests,二分检索
- (最大化平均值)poj2976,Dropping tests
- [POJ2976][分数规划]Dropping tests[水题]
- POJ2976 Dropping tests 最大化平均值(二分)
- poj2976 Dropping tests 【01分数规划】
- [POJ2976]Dropping tests 01分数规划
- [POJ2976]Dropping tests(01分数规划)
- 0/1分数规划 【POJ2976】Dropping tests
- POJ3414-Pots
- Intellij IDEA 下载 激活
- cocos2d-x使用AssetsManager类实现资源的在线更新
- 装饰模式C++实现
- java动态代理机制
- POJ2976-Dropping tests
- Android开发Handler消息机制深入探究
- 暑假集训二顺序表-不敢死队问题
- 进制转换
- inout端口使用方法
- Helloworld
- Cocos2d-x实现资源热更新详解
- 火山/映客直播里用到的库
- linux 下 `dirname $0`