CodeForces - 163B Lemmings
1 second
256 megabytes
standard input
standard output
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.
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.
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.
5 3 2
1 2 3 2 1
1 2 1 2 10
5 2 4
5 3 10
3 4 3 2 1
5 4 3 2 1
4 3 1
Let's consider the first sample case. The fifth lemming (speed 10) gets to the ledge at height 2 in minutes; the second lemming (speed 2) gets to the ledge at height 4 in 2 minutes; the fourth lemming (speed 2) gets to the ledge at height 6 in 3 minutes. All lemmings manage to occupy their positions in 3 minutes.
题意
n个袋鼠要跳k个楼梯,第i个楼梯的高度为i*h。每个袋鼠都有一个速度v和体重m,假如mi<=mj,那么j袋鼠必须跳比i袋鼠更高的楼梯。选出k个袋鼠,问所有袋鼠跳楼梯完成的最短时间是多少?按顺序输出选择袋鼠的序号。
分析
求最短时间,若我们将v以第一关键字,m以第二关键字,从小到大进行排序,那么我们就可以二分时间了。如何检测当前时间是大了还是小了呢,因为限定了k个楼梯,所以按排序结果从后面依次计算每个袋鼠能跳的阶数,若存在k个或以上的袋鼠符合要求,则说明时间够了或者是多了。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1 struct node{
int m,v,pos;
bool operator < (const node&rhs)const{
if(m!=rhs.m) return m<rhs.m;
return v<rhs.v;
}
}d[maxn];
int ans[maxn];
int n,k,h;
int main(){
scanf("%d%d%d",&n,&k,&h);
for(int i=;i<=n;i++) scanf("%d",&d[i].m),d[i].pos=i;
for(int i=;i<=n;i++) scanf("%d",&d[i].v);
sort(d+,d++n);
double l=,r=1e9;
for(int i=;i<;i++){
double mid = (l+r)/2.0;
int cnt=k;
for(int j=n;j>=;j--){ if((mid * d[j].v / h)>=1.0*cnt) cnt--;
}
if(cnt<=) r=mid;
else l=mid;
}
int cnt=k;
for(int j=n;j>=;j--){
// int temp=(int)(r*d[j].v/h);
if((r * d[j].v / h)>=1.0*cnt) ans[cnt--]=d[j].pos;
if(cnt==) break;
}
for(int i=;i<=k;i++) cout<<ans[i]<<" ";
return ;
}
CodeForces - 163B Lemmings的更多相关文章
- CodeForces 163B Lemmings 二分
Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings li ...
- CodeForces 1420E Battle Lemmings
题意 略. \(\texttt{Data Range:}1\leq n\leq 80\) 题解 首先考虑初始状态怎么算答案.很明显直接数满足的不好数,用总的减去不满足的还比较好做.注意到所有不满足的是 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- ASP.NET MVC与WebForm对比
MVC优点:1.分离更彻底,分层清晰,易于维护和扩展.2.验证更加方便快捷.3.无ViewState,页面更加干净4.路由更容易定义url,对SEO比较好.5.强类型VIEW实现,更安全高效. Web ...
- [转帖]召冠总的 Oracle常用的性能诊断语句. --保存学习备查
Copyfrom https://www.cnblogs.com/zhaoguan_wang --1.阻塞及等待事件信息查询-- 查询所有会话的状态.等待类型及当前正在执行的SQL脚本select t ...
- 用Delphi制作动态菜单 该文章《用Delphi制作动态菜单》
---恢复内容开始--- 1.首先,确定动态菜单的数据来源,即要确定动态菜单标题是来自Windows的系统注册表,还是来自一个数据库,或者是来自一个子目录,主要由程序的功能而定.这里假设主窗口名为Ma ...
- scrapy 简单爬虫实验
利用python的模块requests来爬取百度搜索出来的url 使用环境为python3 #!/use/bin/env python # -*- coding:utf-8 -*- import re ...
- BZOJ4832[Lydsy1704月赛]抵制克苏恩——期望DP
题目描述 小Q同学现在沉迷炉石传说不能自拔.他发现一张名为克苏恩的牌很不公平.如果你不玩炉石传说,不必担心,小Q 同学会告诉你所有相关的细节.炉石传说是这样的一个游戏,每个玩家拥有一个 30 点血量的 ...
- .net 手机滑动加载
$(window).scroll(function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).h ...
- hdu 6406 Taotao Picks Apples (2018 Multi-University Training Contest 8 1010)(二分,前缀和)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6406 思路: 暴力,预处理三个前缀和:[1,n]桃子会被摘掉,1到当前点的最大值,1到当前点被摘掉的桃子的 ...
- day30 __new__ 以及单例模式
__new__ # __new__ # object.__new__() class A : def __init__(self): self.x = 1 print("init执行啦&qu ...
- 自学Python3.5-字符串格式化 作用域 递归
一.字符串格式化 二.作用域 三.递归
- BZOJ 3612: [Heoi2014]平衡
3612: [Heoi2014]平衡 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 283 Solved: 219[Submit][Status][ ...