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 = {i1i2, …, 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
最近刚学习了01规划,嗯,这差不多是裸题,然后,没有用binary_search ,学习了Dinkelbach ,其实感觉很迷吧, 会用就行了?
嗯,后面会多练习几道类似的题 。
#include <algorithm>
#include <iostream>
#include <cstdio>
const int N = + ;
using namespace std ;
int n , k , maxn ;
struct node
{
int v , w , id ; double val ;
bool operator < ( const node a ) const { return val > a.val ; }
} num[N] ; void Init( )
{
scanf( "%d%d" , &n , &k ) ;
for( int i = ; i <= n ; ++i )
{ scanf( "%d%d" , &num[i].v , &num[i].w ) ;
num[i].id = i ;
}
} double abse( double a )
{
return ( a < ) ? -a : a ;
} double search( double l )
{
for( int x = ; x <= n ; ++x ) num[x].val = (double)num[x].v - (double)num[x].w * l ;
sort( num + , num + + n ) ;
int tv = , tw = ;
for( int i = ; i <= k ; ++i )
tv += num[i].v , tw += num[i].w ;
double ret = (double)tv/(double)tw ;
return ret ;
} void Solve( )
{
double ans = , tmp ;
while( )
{
tmp = search( ans ) ;
if( abse( ans - tmp ) < 0.001 ) break ;
ans = tmp ;
}
for( int x = ; x <= k ; ++x )
printf( "%d " , num[x].id ) ;
puts( "" ) ; } int main( )
{
Init( ) ;
Solve( ) ;
return ;
}
												

POJ3111 K Best的更多相关文章

  1. POJ3111 K Best(另类背包+二分+变态精度)

    POJ3111 K Best,看讨论区说数据有点变态,精度要求较高,我就直接把循环写成了100次,6100ms过,(试了一下30,40都会wa,50是4000ms) 第一次在POJ上看到下面这种东西还 ...

  2. POJ-3111 K Best---二分求最大化平均值

    题目链接: https://cn.vjudge.net/problem/POJ-3111 题目大意: 卖宝救夫:Demy要卖珠宝,n件分别价值vi 重 wi,她希望保留k件使得 最大. 解题思路: # ...

  3. [POJ3111]K Best(分数规划, 二分)

    题目链接:http://poj.org/problem?id=3111 求选k对数,使得上述式子值最大.容易想到设左边为一个值,对式子变形以下,得到sigma(v-r*w))==0的时候就是最大的,& ...

  4. POJ3111 K Best 2017-05-11 18:12 31人阅读 评论(0) 收藏

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 10261   Accepted: 2644 Case Time ...

  5. POJ3111 K Best —— 01分数规划 二分法

    题目链接:http://poj.org/problem?id=3111 K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissio ...

  6. poj3111 K Best 最大化平均值,二分

    题目:http://poj.org/problem?id=3111 题意:给你n,k,n个数的v.w值,选出k个数,使得v之和/w之和最大化. 思路:一看到题目,这不是赤果果的贪心吗?为什么放在二分专 ...

  7. django模型操作

    Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表        

  8. 基于改进人工蜂群算法的K均值聚类算法(附MATLAB版源代码)

    其实一直以来也没有准备在园子里发这样的文章,相对来说,算法改进放在园子里还是会稍稍显得格格不入.但是最近邮箱收到的几封邮件让我觉得有必要通过我的博客把过去做过的东西分享出去更给更多需要的人.从论文刊登 ...

  9. 【开源】专业K线绘制[K线主副图、趋势图、成交量、滚动、放大缩小、MACD、KDJ等)

    这是一个iOS项目雅黑深邃的K线的绘制. 实现功能包括K线主副图.趋势图.成交量.滚动.放大缩小.MACD.KDJ,长按显示辅助线等功能 预览图 最后的最后,这是项目的开源地址:https://git ...

随机推荐

  1. Java注释模板

    /**   *    * 项目名称:${project_name}   * 类名称:${type_name}   * 类描述:   * 创建人:${user}   * 创建时间:${date} ${t ...

  2. How Does #DeepDream Work?

    How Does #DeepDream Work? Do neural networks hallucinate of electronic dogs? If you’ve been browsing ...

  3. about backbone

    http://presentation.tiddr.de/backbone-presentation/introduction/index.html#Further%20issues http://m ...

  4. Design Tutorial: Learn from Life

    Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B 题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个 ...

  5. Codeforces Round #232 (Div. 1)

    这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...

  6. 基于FFmpeg和Qt的播放器 QtAV库

    http://blog.csdn.net/ibingow/article/details/8144795

  7. 防止服务器宕机时MySQL数据丢失的几种方案

    这篇文章主要介绍了防止服务器宕机时MySQL数据丢失的几种方案,结合实践介绍了Replication和Monitor以及Failover这三个项目的应用,需要的朋友可以参考下. 对于多数应用来说,My ...

  8. JNI编程(二) —— 让C++和Java相互调用(2)

    3.getRamdomOrder() 这个方法会从backend得到一个随机的Order对象(抱歉这里“Random”拼错了),然后再调用java中相应的通知方法来通知foreground.getRa ...

  9. Drawable(3)Color State List Resource

    注意 Color State List Resource 与 Color不同,前者是颜色状态表.根据不同状态显示不同颜色,它是State list,里面有多种颜色,后者只是一个颜色. Color St ...

  10. 【HDOJ】1258 Sum It Up

    典型的深搜,剪枝的时候需要跳过曾经搜索过的相同的数目,既满足nums[i]=nums[i-1]&&visit[i-1]==0,visit[i-1]==0可以说明该点已经测试过. #in ...