poj 3111 best(二分)
来源:互联网 发布:女野人耶哥蕊特 知乎 编辑:程序博客网 时间:2024/06/05 02:04
Problem Link
best
最大化平均值。
分析
需要找的是
AC code
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include <set>#define fi first#define se second#define INF 0x3f3f3f3fusing namespace std;typedef long long LL;typedef pair<LL,LL> PII;const int maxn = 1e5+10;int n,k;struct Jewel{ double v,w; int id;};Jewel a[maxn];double x_cmp;bool cmp(const Jewel& x,const Jewel& y){ return x.v-x_cmp*x.w>y.v-y.w*x_cmp;}bool condition(double x){ x_cmp = x; sort(a,a+n,cmp); double sum = 0; for(int i=0 ; i<k ; ++i)sum+=a[i].v-x_cmp*a[i].w; return sum>=0;}void solve(){ double left =0,right = 1e7+10; while (right>left+1e-5) { double mid = (right+left)/2; if(condition(mid)){ left = mid; }else right = mid; } //std::cout << right <<endl;}int main(){ //freopen("in.txt","r",stdin); while (cin>>n>>k) { for(int i=0 ; i<n ; ++i) { scanf("%lf%lf",&a[i].v,&a[i].w ); a[i].id = i+1; } solve(); for(int i=0 ; i<k ; ++i) printf("%d ",a[i].id); std::cout << '\n'; } return 0;}
0 0
- poj 3111 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(思维+二分)
- 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(二分搜索,最大化平均值)
- POJ - 3111 K Best (二分 + 01分数规划)
- poj3111- POJ - 3111 K Best (二分 + 01分数规划)
- POJ 3111 K Best 二分(最小化平均值)
- poj 3111 K Best 二分搜索 最大化平均值
- POJ 3111 K Best(二分——最大化平均值)
- 工具类
- PAT甲级1061
- 代码冗余到底有没有好处?
- 一招制敌 - 玩转 AngularJS 指令的 Scope (作用域)
- win10配置环境变量
- poj 3111 best(二分)
- OpenCV3.0 Examples学习笔记(7)-ffilldemo.cpp
- 解决角色移动时出现抖动的问题
- build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)'
- 17 - 02 - 30 图解HTTP(04)
- 459. Repeated Substring Pattern#2
- aircrack-ng的安装详解
- JavaScript实现图片轮播组件
- 指针