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 ...
随机推荐
- if 循环的深入理解 哈希表的一种应用
哈希表的值作为一个颜色容器,值默认为标识1, 表示未曾用过,若用过标识为0: 1: 程序第一步 遍历哈希表,查找标识为1 未曾用过的颜色 我用了这个: string colorno_us ...
- 引用类型中的push()、pop()、shift()方法
/** * write by waitingbar1014 * time 2013.10.18 * 用途:常用于如一堆游戏激活码中获得抽取的值 * **/ //有以下一个数组: var arrayli ...
- C# 切换到二级域名,使用Cookie
之前的网站一直用的是一级域名,现因为其他原因,需要使用一个二级域名访问,原先的域名不用了. 使用二级域名后,发现Cookie一直取不到,分析代码发现,原来是需要在设置cookie的时候,把二级域名加上 ...
- C# 出现base-64 字符数组的无效长度的解决办法
最近的一个项目,在传递参数时,在Win2003上正常,在Win7下抛出“base-64 字符数组的无效长度”这样的错误 对比了一下经过Convert.ToBase64String()转换过的参数发现, ...
- ObjC.primitive-methods
Primitive Method "When it comes to subclassing, knowing which methods are ‘primitive’ methods i ...
- Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
环境:Ubuntu 16.04.1 + Django 1.11.15 + Apache 2.4.18 + python 3.5 此篇文章内容提到的第几步,对照以下链接中的步骤 百度云的ubuntu1 ...
- MySQL学习笔记-MySQL体系结构总览
MySQL体系结构总览 不管是用哪种数据库,了解数据库的体系结构都是极为重要的.MySQL体系结构主要由数据库和数据库实例构成. 数据库:物理操作系统文件或者其它文件的集合,在mysql中,数据库文件 ...
- Java 使用jdk自带的wsimport命令生成webservice客户端代码
wsimport -s E:\workspace\givemewords\src -p com.test.service -keep http://localhost:8085/Service/Fun ...
- c++11 时间相关操作练习
博客和书籍资料 来自该地址 https://www.cnblogs.com/qicosmos/category/490693.html 自行编写相应代码进行学习 // TimeTest.cpp: 定义 ...
- rsync (转载)
rsync 编辑 rsync是类unix系统下的数据镜像备份工具——remote sync. 目录 1简介 2特性 3操作流程 ▪ 服务器端启动 ▪ 客户端同步 4安装 1简介编辑 rsy ...
.