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 ...
随机推荐
- OFBIZ安装
1. 安装SVN客户端,从Apache OFBiz Source Repository获取OFBIZ下载地址.此处以12.04为例,下载地址为http://svn.apache.org/repos/a ...
- Windows下Cygwin中使用NCView
1. 使用cygwin的setup.exe安装 NetCDF, HDF5, Curl, libXaw, libICE, udunits, libexpat 和 libpng: 在选择库界面搜索:&qu ...
- Unreal Engine 虚幻引擎宣布对开发者免费
虚幻引擎4现在可供每个人免费使用,而且所有未来的更新都将免费!您可以下载引擎并将其用于游戏开发的各个方面,包括教育.建筑以及可视化,甚至虚拟现 实.电影和动画. 当您发布游戏或应用时,在您的每个游戏在 ...
- effective c++:private继承
如果class间使用private继承关系,编译器就不会自动的将派生类转换为基类,而且private继承而来的成员都变为private属性. private继承意味着根据某物实现出,当我们想要避免重复 ...
- 通过ajax提交form表单
$.ajax({ url : 'deliveryWarrant/update.do', data : $('#myform').serialize(), type : "POST" ...
- c++ List、Vector、Stack、Queue使用
一.List使用 引入头文件#include <list> List基本函数Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比 ...
- Operation not applicable
ClientDataSet.DataSetProvider1 Operation not applicable ClientDataSet1->Open(); 解决办法 1.update new ...
- Apache Spark的部署环境的小记
Spark的单机版便于测试,同时通过SSH用Spark的内置部署脚本搭建Spark集群,使用Mesos.Yarn或者Chef来部署Spark.对于Spark在云环境中的部署,比如在EC2(基本环境和E ...
- 泡泡堂、QQ堂游戏通信架构分析
http://blog.csdn.net/sodme/article/details/468327#comments ————————————————————————————————————————— ...
- MacOSX快捷键
[MacOSX快捷键] 关闭显示器:Shift + Ctrl + 退出键 休眠:Command + Option + 退出键 关机:Ctrl + Option + Command + 退出键 打开文件 ...