POJ 3111 K Best 【二分:最大化平均值】
来源:互联网 发布:网络销售培训课程 编辑:程序博客网 时间:2024/05/29 04:36
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 = {i1, i2, …, 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 21 11 21 3
Sample Output
1 2
Source
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<vector> #include<map> #include<algorithm> using namespace std; #define ll long long #define ms(a,b) memset(a,b,sizeof(a)) const int M=1e5+10; const int inf=0x3f3f3f3f; const int mod=1e9+7; int i,j,k,n,m; int a[M]; int b[M];double y[M];struct node{int num;int v;int w;double y;bool operator < (const node&x) const { return y>x.y; }}p[M];bool cmp(node a,node b){ return a.y>b.y;}int kk[M];bool check(double mid){for(int i=1;i<=n;i++)p[i].y=p[i].v-p[i].w*mid;sort(p+1,p+n+1);double sum=0;for(int i=1;i<=k;i++){ sum+=p[i].y; kk[i]=p[i].num;}return sum>=0;}int main(){while(~scanf("%d%d",&n,&k)){if(n==0&&k==0)break;for(int i=1;i<=n;i++){scanf("%d %d",&p[i].v,&p[i].w); p[i].num=i; } double lb=0,ub=1000000000; for(int i=0;i<100;i++){ double mid=(lb+ub)/2; if(check(mid))lb=mid; else ub=mid; } for(int i=1;i<=k;i++)if(i>1)printf(" %d",kk[i]);else printf("%d",kk[i]); printf("\n"); } return 0;}
- POJ 3111 K Best 【二分:最大化平均值】
- POJ 3111 K Best 二分 最大化平均值
- poj 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(最大化平均值)
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best &&NYOJ 914 (二分+ 贪心,最大化平均值)
- POJ3111 K Best 最大化平均值(二分)
- POJ3111 K Best(二分 最大化平均值)
- poj 3111 K Best && poj 2976(最大化平均值)
- POJ 3111 K Best <最大化平均,二分>
- POJ 3111 K Best 二分(最小化平均值)
- 7_13_F题 K Best(二分、最大化平均值)
- K Best(最大化平均值(二分搜索))
- vs2015编译freeswitch
- svn不知道这样的主机
- vue webpack.base.config.js
- 数据加密解密、公钥、私钥、数字证书
- Shell 教程
- POJ 3111 K Best 【二分:最大化平均值】
- 算法竞赛知识提要4
- 深入理解Spark 2.1 Core (十一):Shuffle Reduce 端的原理与源码分析
- ui-select使用实例
- java中的基本数据类型和引用数据类型内存中的位置
- windows/linux下安装redis以及用java简单操作redis
- java的对象流(序列化与反序列化)
- 俩个大数相乘(java实现)
- webpack