POJ-2976
来源:互联网 发布:安卓处理json实体类 编辑:程序博客网 时间:2024/05/17 05:07
最大化平均值,基本和书上的题型一模一样的,直接二分平均值就好了
#include<cstdio>#include<algorithm>using namespace std;namespace{int n, k, a[1000], b[1000];double d[1000];const double eps = 0.0001;bool check(double x){for (int i = 0; i < n; i++)d[i] = a[i] - x * b[i];sort(d, d + n);double sum = 0;for (int i = 0; i < n - k; i++)sum += d[n - 1 - i];return sum >= 0;}void solve(){double lb = 0, ub = 1, mid;while (ub - lb > eps){mid = (ub + lb) / 2;if (check(mid))lb = mid;elseub = mid;}printf("%d\n", (int) (lb * 100 + 0.5));}}int main(){while (scanf("%d %d", &n, &k), n){for (int i = 0; i < n; i++)scanf("%d", &a[i]);for (int i = 0; i < n; i++)scanf("%d", &b[i]);solve();}return 0;}
0 0
- POJ-2976
- POJ 2976
- POj 2976
- 【POJ】2976
- POJ 3104&&POJ 2976 继续二分搜索。。。
- POJ 2976 参数搜索
- poj 2976 Dropping tests
- POJ 2976 Dropping tests
- poj 2976 分数规划
- POJ 2976 Dropping tests
- poj 2976-Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- POJ-2976-Dropping tests
- poj 2976 Dropping tests
- POJ 2976 Dropping tests
- Poj 2976 Dropping tests
- poj 2976(二分)
- coocos2dx 各种create
- SQLite剖析(10):异步IO模式、共享缓存模式和解锁通知
- scala学习笔记5 (隐式转化/参数/类)
- live writer测试日志
- MySql使用Tips
- POJ-2976
- android - 标题栏进度条
- 算法导论-快速排序-C语言
- Eclipse导入外来工程出错处理
- Python sqlite3库使用
- 基于粒子滤波的目标跟踪基本算法(Matlab)
- 【经典案例】贪吃蛇 AI 的实现 snake AI
- Leetcode 贪心 Longest Consecutive Sequence
- ios-使用标签导航模式