poj 3111 K Best
来源:互联网 发布:海马玩模拟器 for mac 编辑:程序博客网 时间:2024/05/08 04:54
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAX_N = 101000;const int INF = 100000000;int n,m;int v[MAX_N], w[MAX_N];int ans[MAX_N];struct P{ double first; int second; bool operator < (const P& x) const { return first > x.first; }};P y[MAX_N];bool C(double x){ for(int i = 0; i < n; i++){ y[i].first = v[i] - x * w[i]; y[i].second = i; } sort(y, y + n); double sum = 0; for(int i = 0;i < m; i++){ sum += y[i].first; ans[i] = y[i].second; } return sum >= 0; }int main(){ scanf("%d%d", &n, &m); for(int i = 0;i < n; i++){ scanf("%d%d", &v[i], &w[i]); } double ub = INF, lb = 0; for(int i = 0; i < 30 ; i++){ double mid = (lb + ub) / 2; if(C(mid)) lb = mid; ub = mid; } for(int i = 0;i < m; i++){ printf("%d%c", ans[i] + 1, (i == (m-1)) ? '\n' : ' '); } return 0;}
0 0
- POJ 3111 K Best
- poj 3111 K Best
- POJ-3111K Best
- poj 3111 K Best
- POJ 3111K Best
- POJ 3111 K Best 笔记
- poj 3111 K Best 二分
- POJ 3111 K Best 最大化平均值
- POJ 3111 - K Best(二分搜索)
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best <最大化平均,二分>
- poj 3111 K Best(二分)
- POJ 3111 K Best 【二分:最大化平均值】
- POJ 3111 K Best 二分 最大化平均值
- POJ 3111:K Best(思维+二分)
- POJ 3111 K Best 01分治
- K Best POJ
- 初学python,一些总结
- poj 3233 Matrix Power Series
- Zend Framework 入门教程(简体中文版)
- JavaScript基础(基本语法:变量、语句、数组、函数、对象、全局方法以及js与java不同,js与html关联)
- 关于label那些事(居中,换行,获取高度)
- poj 3111 K Best
- poj 3109 Inner Vertices 树状数组+离散化
- C 语言的可变参数表函数的设计
- poj 3061 尺取法
- abstract类举例
- 小说爬虫
- poj 3045 Cow Acrobats
- FMDB
- Map三种遍历方式