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. 关于form表单中button按钮自动提交问题

    坑:点击确认按钮,form表单提交2次,发送后台2次请求 //错误代码: <Button id="btnSubmit" name="btnSubmit" ...

  2. Python的文件读写与存储

    文件读写与存储 7.2. 读写文件 open()返回一个文件对象,最常见的用法带有两个参数:open(filename, mode). >>> f = open('workfile' ...

  3. Kubernetes 命令补全

    yum install -y bash-completionsource /usr/share/bash-completion/bash_completionsource <(kubectl c ...

  4. win10系统下载地址

    Win10正式版微软官方原版ISO系统镜像下载: Win10正式版32位简体中文版(含家庭版.专业版) 文件名: cn_windows_10_multiple_editions_x86_dvd_684 ...

  5. Eclipse 换主题、皮肤、配色,换黑色主题护眼

    Eclipse写android代码时,默认的文本和框架都是白色,长时间使用,显得过于刺眼.这里介绍三种方法换黑色护眼配色. 1.系统设置里更改 2.从Eclipse Marketplace里下载主题 ...

  6. java基础(6)-集合类2

    泛型 泛型:是一种把类型明确的工作推迟到创建对象或者调用方法的时候才去明确的特殊的类型,参数化类型,把类型当做参数一样的传递 好处: 1)把运行时期的问题提前到了编译器期间 2)避免了强制类型转换 3 ...

  7. socket io 记得flush

    public class Client { public static void main(String args[]) throws Exception { //为了简单起见,所有的异常都直接往外抛 ...

  8. IOS 被拒 关于 iPhone running iOS 10.3.1 on Wi-Fi connected to an IPv6 network.

    问题: Guideline 2.1 - Performance Thank you for your resubmission. However, we discovered one or more ...

  9. linux系统内SAMBA共享问题

    最近将项目迁移到了公司服务器上,以后客户端调试和服务端开发都要去链接这台服务器,但是开发就需要调试,也需要log信息,同一局域网内,如何链接服务器并随时查看服务器上的log信息呢? 今天搞了一下,把步 ...

  10. waitpid使用的一点问题

    使用waipid的时候遇到了一个奇怪的问题,将情况简化后描述一下. 有关waitpid的基本介绍参见这里一下:http://www.cnblogs.com/mickole/p/3187770.html ...