K Best
Time Limit: 8000MS   Memory Limit: 65536K
Total Submissions: 8458   Accepted: 2163
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
注意要用G++提交
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
const int MAXN=;
const double EPS=1.0e-6;
struct Node{
int id,v,w;
}a[MAXN];
struct Dou{
int id;
double y;
}b[MAXN];
bool comp(const Dou &no1,const Dou &no2)
{
return no1.y > no2.y;
}
int n,k;
bool test(double x)
{
for(int i=;i<n;i++)
{
b[i].id=a[i].id;
b[i].y=a[i].v-x*a[i].w;
}
sort(b,b+n,comp);
double sum=;
for(int i=;i<k;i++)
{
sum+=b[i].y;
}
return sum>=0.0;
}
int main()
{
while(cin>>n>>k)
{
for(int i=;i<n;i++)
{
a[i].id=i+;
cin>>a[i].v>>a[i].w;
}
double l=0.0;
double r=0x3f3f3f3f;
while(r-l>EPS)
{
double mid=(l+r)/;
if(test(mid)) l=mid;
else r=mid;
}
for(int i=;i<k-;i++)
{
cout<<b[i].id<<" ";
}
cout<<b[k-].id<<endl;
}
return ;
}

POJ3111(最大化平均值)的更多相关文章

  1. POJ-2976 Dropping tests---二分最大化平均值

    题目链接: https://cn.vjudge.net/problem/POJ-2976 题目大意: 给定n个二元组(a,b),扔掉k个二元组,使得剩下的a元素之和与b元素之和的比率最大 解题思路: ...

  2. POJ_3111_K_Best_(二分,最大化平均值)

    描述 http://poj.org/problem?id=3111 n个珠宝,第i个有价值v[i]和重量w[i],要从总选k个,使得这k个的(价值之和)/(重量之和)即平均价值最大,输出选中的珠宝编号 ...

  3. POJ 3111 K Best(最大化平均值)

    题目链接:click here~~ [题目大意]有n个物品的重量和价值各自是Wi和Vi.从中选出K个物品使得单位重量的价值最大,输出物品的编号 [解题思路]:最大化平均值的经典.參见click her ...

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

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

  5. poj 2976(二分搜索+最大化平均值)

    传送门:Problem 2976 参考资料: [1]:http://www.hankcs.com/program/cpp/poj-2976-dropping-tests-problem-solutio ...

  6. 二分算法的应用——最大化平均值 POJ 2976 Dropping tests

    最大化平均值 有n个物品的重量和价值分别wi 和 vi.从中选出 k 个物品使得 单位重量 的价值最大. 限制条件: <= k <= n <= ^ <= w_i <= v ...

  7. 【二分查找-最大化平均值】POJ2976 - Dropping Test

    [题目大意] 给出n组ai和bi,去掉k个使得a的总和除以b的总和最大. [思路] 也就是取(n-k)个数,最大化平均值,见<挑战程序设计竞赛>P144,最后公式为c(x)=((ai-x* ...

  8. POJ 2976 Dropping tests (最大化平均值)

    题目链接:click here~~ [题目大意]给你n个分数的值,要求最小不选k个,使得最后分数相加结果平均值最大 [解题思路]:最大化平均值:參见:click here~~ 代码: #include ...

  9. NYOJ 914 Yougth的最大化【二分/最大化平均值模板/01分数规划】

    914-Yougth的最大化 内存限制:64MB 时间限制:1000ms 特判: No 通过数:3 提交数:4 难度:4 题目描述: Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从 ...

随机推荐

  1. MySQL数据库基本操作(一)

    进入mysql 本地连接: mysql -u用户名 -p 输入密码 qwe123 mysql -uroot -pqwe123 sudo apt-get install mysql-server # p ...

  2. ubuntu关闭631(cups)端口

    在ubuntu17.04环境下使用nmap扫描自己机器,发现631端口处于开启状态,将其输入到浏览器,可以看出是网络打印机的服务: 这个端口开着总是那么的刺眼,(5.12全球爆发的勒索病毒让人不寒而栗 ...

  3. Windows系统 本地文件如何复制到远程服务器

    很多人在使用远程服务器的时候往往要将本地的文件传输到远程服务器内,方法有很多种,下面介绍下如何使用Windows自带的远程桌面连接程序将文件复制到远程服务器内. 1.首先,点击windows开始按钮, ...

  4. eclipse修改端口启动多个tomcat

    参考:https://blog.csdn.net/zl544434558/article/details/47857343 在一个eclipse启动多个tomcat,修改tomcat的端口是不可以的, ...

  5. 中文乱码之myEclipse项目导入时中文乱码(待)

    方法1:检查默认的编码是否设置成utf-8. 步骤如图: window——>preferences... 若Text file encoding 中的编码为 Other == UTF-8 ,则已 ...

  6. QT 使用QTcpServer QTcpSocket 建立TCP服务器端 和 客户端

    1.  如图客户端连接server后,server发送"hello tcp" 给客户端 2. 实例代码 -----------------------------------  s ...

  7. ambari2.4.2在CentOS7上的二次开发

    前言:如果想安装到CentOS7,就一定要将源码在CentOS7上编译,然后安装,否则可能会出现各种问题 目录 源码结构 技术点 编译环境的搭建  安装samba 安装编译环境 整体编译 ambari ...

  8. Codeforces Round #373 (Div. 2) A , B , C

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. Angular表单的本地校验和远程校验

    AngularJS Form 进阶:远程校验和自定义输入项 表单远程校验 HTML代码: <!doctype html> <html ng-app="form-exampl ...

  10. python中利用正则表达式匹配ip地址

    现在有一道题目,要求利用python中re模块来匹配ip地址,我们应如何着手? 首先能想到的是ip地址是数字,正则表达式是如何匹配数字的呢? \d或[0-9] 对于这个问题,不要一下子上来就写匹配模式 ...