POJ 3111 最大化平均值
来源:互联网 发布:怿不甚知书 编辑:程序博客网 时间:2024/05/11 16:15
K Best
Time Limit: 8000MS Memory Limit: 65536K
Total Submissions: 11347 Accepted: 2925
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 = {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 2
1 1
1 2
1 3
Sample Output
1 2
Source
刚开写了一个爆掉,重复利用了以下AC
Northeastern Europe 2005, Northern Subregion
#include<iostream>#include<math.h>#include<cstring>#include<algorithm>#include<set>#include<map>#include<queue>#include<cstdio>#include<vector>const int INF=0x7fffffff;const double EPS=1.0e-6;const int maxn=1e6+10;using namespace std;struct thing{ double v,w; int number;};int n,k;thing T[maxn];bool C(double x){ double temp[maxn]; for(int i=0;i<n;i++) temp[i]=T[i].v-x*T[i].w; sort(temp,temp+n); double sum=0; for(int i=0;i<k;i++) sum+=temp[n-i-1]; return sum>=0.0;}bool cmp(thing a,thing b ){ return a.v<b.v;}int main(){ cin>>n>>k; for(int i=0;i<n;i++) { cin>>T[i].v>>T[i].w; T[i].number=i; } double lb=0; double ub=INF; while((ub-lb)>EPS) { double mid=(ub+lb)/2; if(C(mid)) lb=mid; else ub=mid; } for(int i=0;i<n;i++) { T[i].v=T[i].v-ub*T[i].w; } sort(T,T+n,cmp); for(int i=0;i<k;i++) cout<<T[n-i-1].number+1<<" "; cout<<endl; return 0;}
- poj 3111 最大化平均值
- poj 3111 (最大化平均值)
- POJ 3111 最大化平均值
- POJ 3111 K Best 最大化平均值
- 最大化平均值——poj 3111
- poj 3111 二分求最大化平均值
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best(最大化平均值)
- POJ 3111 K Best 【二分:最大化平均值】
- POJ 3111 K Best 二分 最大化平均值
- POJ 2976 (最大化平均值)
- poj 3111 K Best && poj 2976(最大化平均值)
- poj 3122 Pie (最大化平均值)
- poj 3111 Status List (二分 + 贪心 最大化平均值)
- POJ 3111 K Best(二分搜索,最大化平均值)
- poj 3111 K Best 二分搜索 最大化平均值
- POJ 3111 K Best(二分——最大化平均值)
- poj 3111 K Best(二分-最大化平均值)
- 自定义控件InfoTextView展示个人信息
- 智能天线调试助手之RFFE协议模拟
- 第十一章——编辑UITableView
- lseek 在结尾添加数据
- linux下查看文件第20-30行内容的N种方法及命令介绍
- POJ 3111 最大化平均值
- python里创建多个协程并发执行
- JVM内存问题Error occurred during initialization of VM
- vue2.0组件之间的通信
- java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
- jenkins整合tomcat进行持续deploy
- C/C++:随机数生成
- Android基础技术核心归纳(四)
- Useful JVM Flags – Part 7 (CMS Collector)