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 ...
随机推荐
- c#devexpres TreeList 最简单显示动态值的应用
为了让数据显示在行内,也为熟练一下devexpress treelist 控件, 查找了很多,最多的是先把数据放在datatable 表里边, 然后赋值给treelist的datasource 的 ...
- stl中顺序性容器,关联容器两者粗略解释
什么是容器 首先,我们必须理解一下什么是容器,在C++ 中容器被定义为:在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对像的指针,这种对象类型就叫做容器.很简单,容器就是保存其它对象的对象 ...
- JVM 类加载器 (二)
1.类加载器(ClassLoader)负责加载class文件,class文件在文件开头有特定的文件标识,并且ClassLoader只负责 class 文件的加载,至于class文件是否能够运行则由Ex ...
- java 23种设计模式学习。
一.3大类设计模式:创建型,结构型,行为型. a.5种创建型模式:工厂方法,抽象工厂,单例,建造者,原型. b.7种结构型模式:适配器,装饰器,代理,外观,桥接,组合,享元. c.11种行为型模式:策 ...
- mysql如何查看自己数据库文件所在的位置
mysql如何查看自己数据库文件所在的位置 C:\Program Files\MySQL\MySQL Server 5.5 mysql数据库 方法/步骤 第1步: 打开mysqml文件夹,显示 ...
- ServiceDesk Plus服务管理软件,减轻帮助台负荷,提高IT效率
- 关于进行pdf的每页广告去除、转换word等方案。
pdf转word经常使用的是 软件下载安装破解完成以后进行编辑pdf,可以导出word,效果比一般的word自带的转换效果要好. 在进行pdf的每页去除页脚或者页眉的广告时候,使用pdf的替换功能.这 ...
- sqlserver的substring详细用法
SQL 中的 substring 函数是用来截取一个栏位资料中的其中一部分. 例如,我们需要将字符串'abdcsef'中的‘abd’给提取出来,则可用substring 来实现: select sub ...
- 2019.01.19 bzoj5457: 城市(线段树合并)
传送门 线段树合并菜题. 题意简述:给一棵树,每个节点有bib_ibi个aia_iai民族的人,问对于每棵子树,子树中哪个民族的人最多,有多少人. 思路: 直接上线段树合并,边合并边维护答案即可. ...
- react native底部tab栏切换
1.安装tab栏插件 npm i react-native-tab-navigator --save 2.引入对应的组件和tab插件 import { Platform, StyleSheet, Te ...