Lemmings

题目连接:

http://codeforces.com/contest/163/problem/B

Descriptionww.co

As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.

Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in minutes.

To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.

Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.

Find the way to arrange the lemmings' jump so that time t is minimized.

Input

The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges.

The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming.

The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.

Output

Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.

Sample Input

5 3 2

1 2 3 2 1

1 2 1 2 10

Sample Output

5 2 4

Hint

题意

给你n个袋鼠,然后袋鼠要跳楼梯,你需要选出k个袋鼠出来,跳k个楼梯

第一个楼梯的高度为h,第二个为2h,第三个为3h,第n个为nh

每个袋鼠有两个属性,体重和速度,要求如果i的体重大于j的话,i只能跳比j高的楼梯

你需要使得k个袋鼠跳的最慢的袋鼠的时间最小,然后让你把方案输出

题解:

二分最后的时间,然后贪心的去选就好了

袋鼠按照体重为第一关键字,速度第二关键字从小到大排序

贪心去选

注意:精度有毒,最好就不要用eps这玩意儿。。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
pair<pair<int,int>,int>p[maxn];
int ans[maxn];
int n,k,h;
int check(double x)
{
int tot = 1;
for(int i=1;i<=n;i++)
{
if(1.0*tot*h<=p[i].first.second*x)
{
ans[tot]=p[i].second;
tot++;
if(tot>k)return 1;
}
}
return 0;
}
int main()
{
scanf("%d%d%d",&n,&k,&h);
for(int i=1;i<=n;i++)
scanf("%d",&p[i].first.first);
for(int i=1;i<=n;i++)
scanf("%d",&p[i].first.second);
for(int i=1;i<=n;i++)
p[i].second=i;
sort(p+1,p+1+n);
double l = 0.0,r = 1000000000.0;
for(int i=1;i<=100;i++)
{
double mid = (l+r)/2.0;
if(check(mid))r=mid;
else l=mid;
}
check(r);
for(int i=1;i<=k;i++)
printf("%d ",ans[i]);
printf("\n");
}

CodeForces 163B Lemmings 二分的更多相关文章

  1. CodeForces - 163B Lemmings

    B. Lemmings time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  2. codeforces 1165F1/F2 二分好题

    Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...

  3. codeforces 732D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...

  4. CodeForces 359D (数论+二分+ST算法)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...

  5. CodeForces - 589A(二分+贪心)

    题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  7. CodeForces - 1059D(二分+误差)

    链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...

  8. Letters CodeForces - 978C (二分)

    Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they a ...

  9. Codeforces 475D 题解(二分查找+ST表)

    题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...

随机推荐

  1. Solution multisite htaccess cleanURL

    My solution to getting Clean URL working with my multisite setup drupal 4.7 I added Alias to my http ...

  2. As3 计算两个日期之间的天数差

    /*日期转YYYYMMDD*/ formDate.fullYear+""+(formDate.month<10?("0"+formDate.month): ...

  3. LR之配置端口映射(port mapping)

    1.那些协议需要配置 tools-recording_options-network-port mapping 2.定义端口映射 3.自动检测原理 4.特殊情况

  4. spark connect to Cassandra problem

    Cassandra rowkey is Blob type, cannot select by spark. How?

  5. 理解KMP

    KMP字符串模式匹配通俗点说就是一种在一个字符串中定位另一个串的高效算法.简单匹配算法的时间复杂度为O(m*n),KMP匹配算法,可以证明它的时间复杂度为O(m+n).. 一.简单匹配算法 先来看一个 ...

  6. Ubuntu 下无法Tab键自动补全功能解决办法

    在Ubuntu下 使用Tab键报错:cannot create temp file for here-document: no space left on device 解决: rm -rf /var ...

  7. 【Maven】Maven下载源码和Javadoc的方法

    1:Maven命令下载源码和javadocs 当在IDE中使用Maven时如果想要看引用的jar包中类的源码和javadoc需要通过maven命令下载这些源码,然后再进行引入,通过mvn命令能够容易的 ...

  8. <转>Linux环境进程间通信(三)

    原文链接:http://www.ibm.com/developerworks/cn/linux/l-ipc/part3/index.html 原文内容: 消息队列(也叫做报文队列)能够克服早期unix ...

  9. Linux下的grep搜索命令详解(二)

    grep与正规表达式  字符类 字符类的搜索:如果我想要搜寻 test 或 tast 这两个单词时,可以发现到,其实她们有共通的 't?st' 存在-这个时候,我可以这样来搜寻: [root@www ...

  10. gdb之x命令

    [gdb之x命令] 可以使用examine命令(简写是x)来查看内存地址中的值.x命令的语法如下所示: x/<n/f/u> <addr> n.f.u是可选的参数. n是一个正整 ...