Gym
来源:互联网 发布:斗鱼点播软件 编辑:程序博客网 时间:2024/06/06 18:37
Doomsday comes in t units of time. In anticipation of such a significant eventn people prepared m vaults in which, as they think, it will be possible to survive. But each vault can accommodate onlyk people and each person can pass only one unit of distance per one unit of time. Fortunately, all people and vaults are now on the straight line, so there is no confusion and calculations should be simple.
You are given the positions of the people and the vaults on the line. You are to find the maximal number of people who can hide in vaults and think they will survive.
The first line contains four integers n,m, k andt (1 ≤ n, m, k ≤ 200000,1 ≤ t ≤ 109) separated by spaces — the number of people, the number of vaults, the capacity of one vault and the time left to the Doomsday.
The second line contains n integers separated by spaces — the coordinates of the people on the line.
The third line contains m integers separated by spaces — the coordinates of the vaults on the line.
All the coordinates are between - 109 and109, inclusively.
Output one integer — the maximal number of people who can hide in vaults and think they will survive.
2 2 1 545 5540 60
2
2 2 1 545 5440 60
1
2 2 2 545 3540 60
2
3 3 1 540 45 4545 50 50
3
思路:贪心问题,把棺材作为研究对象,从左到右遍历一遍即可;
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int peo[200005],res[200005];int main(){int n,m,k,t;while(scanf("%d %d %d %d",&n,&m,&k,&t)!=EOF){for(int i=0;i<n;i++)scanf("%d",&peo[i]);for(int i=0;i<m;i++)scanf("%d",&res[i]);sort(peo,peo+n);sort(res,res+m);int now=0,cnt=0,ans=0;for(int i=0;i<m;i++){cnt=k;int j=now;for(;peo[j]<=res[i]+t && j<n && cnt;j++){if(peo[j]>=res[i]-t){ans++;cnt--;}}now=j;if(j==n) break;}printf("%d\n",ans);}return 0;}
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- C语言好难——几个宏定义__DATE__,__TIME__,__FILE__,__LINE__
- ORM “杀器”之 JOOQ
- block的使用
- Android RenderScript模糊图片失败_虚化图片失败_的原因
- 单向链表的定义及基本操作
- Gym
- hdu 5997 rausen loves cakes
- 最大生成树Kruskal
- Fire Net
- 【学习】Hadoop大数据平台架构与实践--基础篇中
- 线程池实现原理
- RTMP协议学习
- pjsip中面向对象思路
- [读书笔记]H.265/HEVC:原理,标准与实现