zoukankan      html  css  js  c++  java
  • codeforces Gym 100187F F

    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=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';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=0;i<n;i++)
        {
            int x=read();
            a[i].x=x-t;
            a[i].y=x+t;
        }
        for(int j=0;j<m;j++)
            b[j]=read();
        sort(a,a+n,cmp);
        sort(b,b+m);
        int ans=0;
        int j=0;
        for(int i=0;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;
    }
  • 相关阅读:
    敏捷教练要如何平衡工作与生活
    CSS 盒模型
    解决浩方显示no ping的问题,罪魁祸首在NOD32的设置上
    关于一个JS功能实现的思维方式
    10个最好的免费Javascript图表生成方案
    微软对Dynamics CRM的开发工具和SaaS功能做出升级
    MSDeploy:让部署和同步网站自动化
    Javascript的私有成员
    简单的字符串模板
    敏捷合同编写指南
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4657697.html
Copyright © 2011-2022 走看看