K Best [二分]
来源:互联网 发布:zookeeper mysql 实战 编辑:程序博客网 时间:2024/06/05 04:30
这题与http://blog.csdn.net/qer_computerscience/article/details/77601173
一模一样。
#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<bitset>#include<algorithm>#include<map>#include<set>#include<queue>#include<vector>#include<cstdlib>#include<list>#include<stack>#include<cmath>#include<iomanip>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")typedef long long LL;void debug() {cout << "ok running!" << endl;}int n, k;struct node{ int v, w, id; double x; bool operator < (node& b) { return x > b.x; }} a[100005];bool check(double mid){ for(int i = 0; i < n; ++i) a[i].x = a[i].v - mid*a[i].w; sort(a, a+n); double sum = 0; for(int i = 0; i < k; ++i) sum += a[i].x; if(sum >= 0) return 1; else return 0;}int main(){ ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif // ONLINE_JUDGE while(cin >> n >> k) { for(int i = 0; i < n; ++i) { int x, y; cin >> x >> y; a[i].id = i+1; a[i].v = x, a[i].w = y; } double l = 0.0, r = 999999999.0; while(r - l > 1e-4) { double mid = (l+r) / 2; //cout << mid << endl; if(check(mid)) l = mid; else r = mid; } for(int i = 0; i < k-1; ++i) cout << a[i].id << " "; cout << a[k-1].id << endl; } return 0;}
阅读全文
0 0
- K Best [二分]
- POJ3111 K Best 二分搜索
- poj 3111 K Best 二分
- POJ 3111 - K Best(二分搜索)
- poj K Best 最大化平均值 二分搜索
- POJ3111 K Best 最大化平均值(二分)
- POJ3111 K Best(二分 最大化平均值)
- POJ 3111 K Best <最大化平均,二分>
- poj 3111 K Best(二分)
- 求改poj3111 K Best二分
- POJ 3111 K Best 【二分:最大化平均值】
- POJ 3111 K Best 二分 最大化平均值
- POJ 3111:K Best(思维+二分)
- K Best poj 3111 (01分数规划---二分搜索)
- poj 3111 K Best ,二分,牛顿迭代
- POJ 2976 Dropping tests、3111 K Best (二分搜索)
- POJ 3111 K Best (01分数规划+二分)
- POJ 3111 K Best(二分搜索,最大化平均值)
- 前端Js框架汇总
- 单例模式总结
- 1.4 基本语句
- math类以及单例模式
- mysql表情符录入异常:Incorrect string value: ...for column...
- K Best [二分]
- c#_初学者基础语法及运算符号
- CEF3:用CEF3实现最简单的浏览器
- openlayer读取三种类型的本地瓦片的计算公式
- Maven打包的三种方式
- 1.5 函数和预处理
- shiro学习——高级概述(二)
- STL空间配置器的union obj
- 内存数据库技术选型