K Best
Time Limit: 8000MS   Memory Limit: 65536K
Total Submissions: 10507   Accepted: 2709
Case Time Limit: 2000MS   Special Judge

Description

Demy has n jewels. Each of her jewels has some value vi and weight wi.

Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. She decided to keep such jewels that their specific value is as large as possible. That is, denote the specific value of some set of jewels S = {i1i2, …, ik} as

.

Demy would like to select such k jewels that their specific value is maximal possible. Help her to do so.

Input

The first line of the input file contains n — the number of jewels Demy got, and k — the number of jewels she would like to keep (1 ≤ k ≤ n ≤ 100 000).

The following n lines contain two integer numbers each — vi and wi (0 ≤ vi ≤ 106, 1 ≤ wi ≤ 106, both the sum of all vi and the sum of all wi do not exceed 107).

Output

Output k numbers — the numbers of jewels Demy must keep. If there are several solutions, output any one.

Sample Input

3 2
1 1
1 2
1 3

Sample Output

1 2

Source

Northeastern Europe 2005, Northern Subregion
题意:
有n个宝贝,每个宝贝有价值v和质量w要求取k个宝贝使得sum(v)/sum(w)最大,输出这k个宝贝的编号
代码:
//二分题,设最终结果是s,sum(分子)/sum(分母)=s,组成s的必然有a/b>=s和a/b<=s =>
//a-s*b>=0和a-s*b<=0,因此二分s值然后按照a-s*b从大到小排序依次取前k个看结果是否
//大于等于s
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const double esp=0.000001;
int n,k;
double x;
struct Lu{
int id;
double v,w;
bool operator < (const Lu &p)const{
return v-x*w>p.v-x*p.w;
}
}L[maxn];
bool solve(double m){
x=m;
sort(L,L+n);
double tmp1=,tmp2=;
for(int i=;i<k;i++){
tmp1+=L[i].v;
tmp2+=L[i].w;
}
return tmp1-m*tmp2>=0.0;
}
int main()
{
while(scanf("%d%d",&n,&k)==){
for(int i=;i<n;i++){
scanf("%lf%lf",&L[i].v,&L[i].w);
L[i].id=i;
}
double l=0.0,r=10000000.0;
while(r-l>esp){
double m=(l+r)/2.0;
if(solve(m)){
l=m;
}else r=m;
}
for(int i=;i<k;i++)
printf("%d%c",L[i].id+,i==k-?'\n':' ');
}
return ;
}

POJ 3111 二分的更多相关文章

  1. poj 3111 K Best 最大化平均值 二分思想

    poj 3111 K Best 最大化平均值 二分思想 题目链接: http://poj.org/problem?id=3111 思路: 挑战程序竞赛书上讲的很好,下面的解释也基本来源于此书 设定条件 ...

  2. POJ 3111 K Best(01分数规划)

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 9876   Accepted: 2535 Case Time ...

  3. POJ - 2018 二分+单调子段和

    依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...

  4. POJ 3111 K Best(二分答案)

    [题目链接] http://poj.org/problem?id=3111 [题目大意] 选取k个物品,最大化sum(ai)/sum(bi) [题解] 如果答案是x,那么有sigma(a)>=s ...

  5. POJ - 3111 K Best 0-1分数规划 二分

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 12812   Accepted: 3290 Case Time ...

  6. POJ 3111 K Best ( 二分 )

    题意 : 给出 N 个物品的价值和重量,然后要求选出 K 个物品使得选出来物品的单位重量价值最大,最后输出被选物品的编号. 分析 :  很容易去想先算出每个物品的单位价值然后升序排序取前 K 个,但是 ...

  7. POJ 3111 K Best 最大化平均值 [二分]

    1.题意:给一共N个物品,每个物品有重量W,价值V,要你选出K个出来,使得他们的平均单位重量的价值最高 2.分析:题意为最大化平均值问题,由于每个物品的重量不同所以无法直接按单位价值贪心,但是目标值有 ...

  8. POJ - 3111 K Best(二分)

    包含一些ai和bi的集用S来表示,x = max(sigma(ai)/sigma(bi),i 属于S) ,k 表示S的大小,k= |S|. x和k之间具有单调性.k0 < k1 → x0 ≥ x ...

  9. poj 3621 二分+spfa判负环

    http://poj.org/problem?id=3621 求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 0/1整数划分问题 令在一个环里,点权为v[i], ...

随机推荐

  1. 2018牛客多校第二场a题

    一个人可以走一步或者跳x步,但不能连着跳,问到这个区间里有几种走法 考虑两种状态  对于这一点,我可以走过来,前面是怎么样的我不用管,也可以跳过来但是,跳过来必须保证前一步是走的 dp[i][0]表示 ...

  2. 初涉 Deep Drive Dataset

    Berkeley 大学最近推出的针对自动驾驶的街景数据集,号称比 Cityscapes 数据量更大,可泛化性更好. 语义实例分割(Semantic Instance Segmentation) 数据集 ...

  3. 概要梳理kafka知识点

    主要是梳理一下kafka学习中的一些注意点,按照消息的流动方向进行梳理.详细的kafka介绍推荐看骑着龙的羊的系列博客,具体的某一块的知识点,可以参考我给出的一些参考文章. 1. kafka在系统中的 ...

  4. SpringCloud IDEA 教学 (三) Eureka Client

    写在前头 本篇继续介绍基于Eureka的SpringCloud微服务搭建,回顾一下搭建过程, 第一步:建立一个服务注册中心: 第二步:建立微服务并注入到注册中心: 第三步:建立client端来访问微服 ...

  5. html5 canvas绘制环形进度条,环形渐变色仪表图

    html5 canvas绘制环形进度条,环形渐变色仪表图                                             在绘制圆环前,我们需要知道canvas arc() 方 ...

  6. lintcode-143-排颜色 II

    143-排颜色 II 给定一个有n个对象(包括k种不同的颜色,并按照1到k进行编号)的数组,将对象进行分类使相同颜色的对象相邻,并按照1,2,...k的顺序进行排序. 注意事项 You are not ...

  7. 关于char, wchar_t, TCHAR, _T(),L,宏 _T、TEXT,_TEXT、L

    char :单字节变量类型,最多表示256个字符, wchar_t :宽字节变量类型,用于表示Unicode字符, 它实际定义在<string.h>里:typedef unsigned s ...

  8. .net 简体转换繁体实例,繁体转换简体 Encode.dll、下载

    在项目中先引用Encode.dll  下面是下载地址: Encode.dll ChineseConverter.dll 1.html页面代码 <%@ Page Language="C# ...

  9. 【Linux】- apt-get命令

    apt-get,是一条linux命令,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载软件或操作系统. Advanced Package Tool,又名apt-g ...

  10. UML图之协作图

    创建方法: 1,new----collaboration diagram 2,根据序列图按F5转换 增加对象链接(图2-4-4)    (1) 选择Object Link 工具栏按钮. (2) 单击要 ...