F. Doomsday

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100187/problem/F

Description

Doomsday comes in t units of time. In anticipation of such a significant event n people prepared m vaults in which, as they think, it will be possible to survive. But each vault can accommodate only k 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.

Input

The first line contains four integers n, m, k and t (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 and 109, inclusively.

Output

Output one integer — the maximal number of people who can hide in vaults and think they will survive.

Sample Input

2 2 1 5
45 55
40 60

Sample Output

2

HINT

题意

有n个人,m个藏身处,每个藏身处可以藏k个人,一个人可以往左边走t米,往右边走t米,问你最后能躲几个人?

题解:

这是一个区间覆盖问题,类似贪心搞一搞就行了

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200101
#define mod 1000000009
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
int x,y;
};
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
ll flag[maxn];
node a[maxn];
ll b[maxn];
ll c[maxn];
int main()
{
ll n=read(),m=read(),k=read(),t=read();
for(int i=;i<n;i++)
{
int x=read();
a[i].x=x-t;
a[i].y=x+t;
}
for(int j=;j<m;j++)
b[j]=read();
sort(a,a+n,cmp);
sort(b,b+m);
int ans=;
int j=;
for(int i=;i<n;i++)
{
if(j==m)
break;
while(b[j]<a[i].x&&j<m)
j++;
if(j==m)
break;
if(a[i].y>=b[j])
{
ans++;
c[j]++;
if(c[j]==k)
j++;
}
}
cout<<ans<<endl;
}

codeforces Gym 100187F F - Doomsday 区间覆盖贪心的更多相关文章

  1. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  2. UVa 10382 Watering Grass (区间覆盖贪心问题+数学)

    题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...

  3. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  4. Codeforces Gym 100513F F. Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  5. Codeforces Gym 100513F F. Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  6. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  7. GYM 101173 F.Free Figurines(贪心||并查集)

    原题链接 题意:俄罗斯套娃,给出一个初始状态和终止状态,问至少需要多少步操作才能实现状态转化 贪心做法如果完全拆掉再重装,答案是p[i]和q[i]中不为0的值的个数.现在要求寻找最小步数,显然要减去一 ...

  8. POJ2376Cleaning Shifts(区间覆盖贪心)

    应该还是蛮简单的一题,但是因为模拟太差,一直没调出来....... \(显而易见的应该按照左区间从小到大排序,相等按照右区间大到小排序\). \(那么第一个区间的l一定要是1,而且必拿(否则没有区间能 ...

  9. Codeforces Gym H. Hell on the Markets 贪心

    Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vj ...

随机推荐

  1. Learning Vector

    题意: 给出n组x,y增量,从(0,0)开始以x,y坐标增加后等到的终点坐标,可以构成一个面积,再以这个终点为起点再增加,以此类推,使用增量顺序不同,得到的面积不,求用k组增量能得到的最大的面积. 分 ...

  2. Drupal处理缓存的方式

    Drupal的后台数据库中有很多以cache开头的表,这些都是Drupal的缓存数据表. Drupal的缓存机制使用了接口方式,所有的缓存对象都必须实现DrupalCacheInterface接口: ...

  3. NewtonPrincipia_物体的运动_求向心力

    NewtonPrincipia_物体的运动_求向心力 让我们看一下十七世纪的被苹果砸中的艾萨克,是怎样推导出向心力公式的 在现在的观点看来,其中涉及到的很多没有符号表示的微分量.下面的内容只是叙述了推 ...

  4. 软件工程个人项目-Word frequency program by11061167龚少波

    (一)工程设计时间预计 1.代码编写:4小时 熟悉Visual studio 2012的使用 : 程序代码部分主要分为三个步骤: (1)主函数的构建,包括各种函数调用及输入输出部分: (2)对目标文件 ...

  5. 使用ncc分析代码

    1 ncc是一个编译器, 用于输出程序的一些调用信息等, 可以查看函数调用关系, 支持函数指针, 查看数据结构和代码. 可以用来分析和理解代码. “" ... with ncc, in le ...

  6. 最好的10本适用于初学者阅读的javaScript和jQuery书籍

    现在有许多方式学习新的内容,但是对于刚开始学习和寻找真正沉迷其中的平和状态的人而言,经典的纸质书籍依旧是首选.我发现阅读一本纸质书籍会让自己远离那些在使用电脑和平板时出现的令人不安的情绪.电子书和播客 ...

  7. Spark on Yarn遇到的几个问题

    1 概述 Spark的on Yarn模式,其资源分配是交给Yarn的ResourceManager来进行管理的,但是目前的Spark版本,Application日志的查看,只能通过Yarn的yarn ...

  8. UDP广域网,局域网通信-原理分析,穿透技术

    一.UDP局域网通信. 这个比较简单,关于局域网中的2台或者更多的计算机之间的UDP通信,网络上一大把,直接复制粘贴就可以使用,原理也非常简单.所以,本文不做详细介绍. 二.UDP广域通信(包括路由器 ...

  9. 清空easyui datagrid

    $('#grid').datagrid("loadData",{total:0,rows:[]});

  10. KMP算法——Javascript实现

    腾讯和阿里的笔试刚过去了,里面有很多题都很值得玩味的.之前Blog积累的很多东西,还要平时看的书,都有很大的帮助.这个深有体会啊! 例如,腾讯有一道算法题是吃香蕉(好邪恶的赶脚..),一次吃一根或者两 ...