POJ3111 K Best 2017-05-11 18:12 31人阅读 评论(0) 收藏
|
K Best
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.
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 Output Output k numbers — the numbers of jewels Demy must keep. If there are several solutions, output any one. Sample Input 3 2 Sample Output 1 2 Source
Northeastern Europe 2005, Northern Subregion
|
[Submit] [Go Back] [Status]
[Discuss]
——————————————————————————————————
题目的的意思是给出n个分数取其中m个,要求分子之和与分母之和之比最大
思路:二分+验证
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int n,m;
struct node
{
int a,b,id;
} p[100005];
double k; bool cmp(node a,node b)
{
double x=a.a-(a.b*k);
double y=b.a-(b.b*k);
return x>y;
} bool ok(double mid)
{
k=mid;
sort(p,p+n,cmp);
LL x=0,y=0;
for(int i=0; i<m; i++)
{
x+=p[i].a;
y+=p[i].b;
}
double ans=x*1.0/y;
if(ans>=mid)
return 1;
return 0; } int main()
{
while(~scanf("%d%d",&n,&m)&&(m||n))
{
for(int i=0; i<n; i++)
scanf("%d%d",&p[i].a,&p[i].b),p[i].id=i+1;
double l=0,r=1e6;
while(r-l>1e-5)
{
double mid=(l+r)/2;
if(ok(mid))
l=mid;
else
r=mid;
}
int q=0;
for(int i=0; i<m; i++)
{
if(q++)
printf(" ");
printf("%d",p[i].id);
}
printf("\n");
}
return 0;
}
POJ3111 K Best 2017-05-11 18:12 31人阅读 评论(0) 收藏的更多相关文章
- 团体程序设计天梯赛L2-002 链表去重 2017-03-22 18:12 25人阅读 评论(0) 收藏
L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...
- POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1892 Desc ...
- HDU2544 最短路 2017-04-12 18:51 31人阅读 评论(0) 收藏
最短路 Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- URAL1991 The battle near the swamp 2017-04-12 18:07 92人阅读 评论(0) 收藏
The battle near the swamp Gungan: Jar Jar, usen da booma! Jar Jar: What? Mesa no have a booma! Gun ...
- MS SQLServer 批量附加数据库 分类: SQL Server 数据库 2015-07-13 11:12 30人阅读 评论(0) 收藏
************************************************************ * 标题:MS SQLServer 批量附加数据库 * 说明:请根据下面的注释 ...
- Eclipse和MyEclipse的区别 分类: 编程工具 2015-07-18 11:12 23人阅读 评论(0) 收藏
今天,在一个Q群里有人问Eclipse和MyEclipse的区别.虽然对于知道的人来说答案很简单,但是对于不知道的人来说就很难,很多问题也都是这样的,会者不难,难者不会. 其实,网上搜搜答案就挺多的, ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
随机推荐
- 操作系统之CPU管理的直观想法
计算机:是工具,帮助解决实际问题 操作系统,是为了方便使用硬件 计算机模型: 图灵机,模拟人类计算 起初的图灵机就像一个只会做一道菜的厨师 通用图灵机,核心是设置控制器动作(修改控制器),把逻辑读入控 ...
- PAT乙级 解题目录
有些题做得可能比较傻,有好方法,或者有错误还请告诉我,多多指教=.= 思路比较好的题目我都有讲的很详细. 剩下三道题有待优化,等改好了再上传. 标题 题目链接 解题链接 1001 害死人不偿命的( ...
- Nginx如何设置禁止IP访问网站
需要禁止IP访问网站.在相关的server中设置相关的限制即可.
- libpcap 库使用(一)
参考资料: http://www.tcpdump.org/ DESCRIPTION The Packet Capture library provides a high level interface ...
- tomcat+bean例子
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\app\WEB-INF\classes\文件夹下 建立beanTestPa ...
- SyntaxError: missing ; before statement
做分页功能,遇到了很坑的事情.前台一直报错:SyntaxError: missing ; before statement 最后发现解决办法是eval("("+s+")& ...
- 【搜索】棋盘问题(DFS)
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- Java类加载机制及自定义加载器
转载:https://www.cnblogs.com/gdpuzxs/p/7044963.html Java类加载机制及自定义加载器 一:ClassLoader类加载器,主要的作用是将class文件加 ...
- DOM-DOMTree-查找
1. 什么是DOM: Document Object Model 专门操作网页内容的API js=ES+DOM+BOM DOM是由W3C指定的API标准 为什么: 为了统一各个浏览器操作网页内容的AP ...
- 2018.06.27Dual Core CPU(最小割)
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 26136 Accepted: 11270 Cas ...
.