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 ...
随机推荐
- 解决android.os.NetworkOnMainThreadException
好久不写Android代码手都生了,找出自己之前写的程序发现跑不了了,也没啥特别的错误提示,就看到一句有用的错误Caused by: android.os.NetworkOnMainThreadExc ...
- Linux下gdb使用整理记录
1.创建cpp文件:vim sourcefile.cpp 2.生成可执行文件:g++ -g sourcefile.cpp -o exename ------据说是要必须加上-g参数,否则不可调试 3. ...
- Having the Result Set of a Stored Proc Sent to You by RSS Feed.
Having the Result Set of a Stored Proc Sent to You by RSS Feed. by JBrooks 14. 十二月 2010 12:44 I wa ...
- html5 拖拽
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 第三百四十四天 how can I 坚持
三言诗,把自己的心情,想要说的话用三句话诗意的表达出来.像: 烦===>好想睡一觉,待日落,盼天明. 愁====>待到花开花落,闲庭信步,蹋碎一世忧愁. 三句话,可以表达的很好. 老是感觉 ...
- Extjs4.2纯前台导出Excel总结
前段时间做了两个项目,用到了Extjs4.2纯前台导出Excel,遇到很多的问题,从网上也找了很多资料,在这里总结一下,做一个记录: 使用方法: 1.下载extexcel文件包,这里可以下载http: ...
- beantool.map2Bean(map,obj)
- 安装php5.5
安装php5.5 ./configure --prefix=/usr/local/php5.5.14/ --with-apxs2=/usr/local/apache2.2.27/bin/apxs -- ...
- QListWidgetItem带上颜色的问题
new_item = QListWidgetItem(_fromUtf8(item_content), self.listWidget) 首先创建一个QListWidgetItem,第一个参数内容是I ...
- ASP.NET MVC- 解决HTML转码
在MVC里从Controller发送一段带有HTML的文字到View视图时,MVC是会将这段代码进行转码的. 一.使用MvcHtmlString转HTML转码 如果想不让这段文字进行转码,以HTML的 ...