CodeForces 163B Lemmings 二分
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 二分的更多相关文章
- CodeForces - 163B Lemmings
B. Lemmings time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- codeforces 732D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- CodeForces - 589A(二分+贪心)
题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...
- 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 ...
- CodeForces - 1059D(二分+误差)
链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...
- Letters CodeForces - 978C (二分)
Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they a ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
随机推荐
- TextView------文字底部或者中间加横线
promotionLinkText = (TextView) this .findViewById(R.id. text_promotion_link ); 中间加横线 promotionLinkTe ...
- Drupal如何更新注册表?
Drupal的注册表是指registry和registry_file两个数据表.前一个表保存所有可用的类和接口以及它们所对应的文件,后一个表保存每个文件的hash码. 1. 将所有需要更新的文件都汇总 ...
- GC Buffer Busy Waits处理(转载)
与单实例不同,在RAC环境中,由于多节点的原因,会因为节点间的资源争用产生GC类的等待,而这其中,GC Buffer Busy Waits又是最为常见的,从性能角度上说,RAC是把双刃剑,用的好,能够 ...
- python代码编程规范
一.内容格式 1.注释部分:模块名及简介(一般用一行写完),模块描述(包含各类方法),其它描述(注意点,功能,示例等,可以分多段) 2.导入模块:Import XXX 3.全局变量定义:wantobj ...
- [转]Chrome浏览器的离线安装包下载地址
每当chrome有更新之后,都有不少用户想要下载离线版的安装文件,但苦于找不到下载地址而发愁,其实这个问题很简单,下面我来分享一下方法(仅针对Windows操作系统): 对于稳定版(正式版)Chrom ...
- 指针数组 数组指针的区别.xml
pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...
- PHP 新建动态类的代码
$testObject=(object)array(); $testObject->first="firstValue"; var_dump($testObject); $t ...
- php 高效分页
mysql.php 获取数据库中的记录,完全个人经验总结,仅供参考!<?php/***PHP+MYSQL数据库基本功能*http://blog.csdn.net/yown*/########## ...
- PHP强大的内置filter (一)
<?php #PHP内置的validate filter $input_data = True; $result = filter_var($input_data,FILTER_VALIDATE ...
- Spark RDD概念学习系列之为什么会引入RDD?(一)
为什么会引入RDD? 我们知道,无论是工业界还是学术界,都已经广泛使用高级集群编程模型来处理日益增长的数据,如MapReduce和Dryad.这些系统将分布式编程简化为自动提供位置感知性调度. ...