• CF555B 贪心


    http://codeforces.com/problemset/problem/555/B

    B. Case of Fugitive
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.

    The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: island i has coordinates [li, ri], besides, ri < li + 1 for 1 ≤ i ≤ n - 1.

    To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length a can be placed between the i-th and the (i + 1)-th islads, if there are such coordinates of x and y, that li ≤ x ≤ rili + 1 ≤ y ≤ ri + 1 and y - x = a.

    The detective was supplied with m bridges, each bridge can be used at most once. Help him determine whether the bridges he got are enough to connect each pair of adjacent islands.

    Input

    The first line contains integers n (2 ≤ n ≤ 2·105) and m (1 ≤ m ≤ 2·105) — the number of islands and bridges.

    Next n lines each contain two integers li and ri (1 ≤ li ≤ ri ≤ 1018) — the coordinates of the island endpoints.

    The last line contains m integer numbers a1, a2, ..., am (1 ≤ ai ≤ 1018) — the lengths of the bridges that Andrewid got.

    Output

    If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print n - 1 numbers b1, b2, ..., bn - 1, which mean that between islands i and i + 1 there must be used a bridge number bi.

    If there are multiple correct answers, print any of them. Note that in this problem it is necessary to print "Yes" and "No" in correct case.

    Sample test(s)
    input
    4 4
    1 4
    7 8
    9 10
    12 14
    4 5 3 8
    
    output
    Yes
    2 3 1 
    
    input
    2 2
    11 14
    17 18
    2 9
    
    output
    No
    
    input
    2 1
    1 1
    1000000000000000000 1000000000000000000
    999999999999999999
    
    output
    Yes
    1 
    
    Note

    In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14.

    In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist.

    /**
    CF555B 贪心
    题目大意:给定一些不连续的区间用给定长度的线段将这些区间连起来。要求线段长度的两个顶点必须在连接的两个区间上,
              问能否够将全部的区间连接成一个区间
    解题思路:对于每个要连接的空隙(即相邻的两个区间之间的部分)求出可用线段的最短长度x和最长长度y,依照x递减,x相等y递减的
              方式排序。将须要的线段放到给set中。从前到后遍历空隙。每次取第一个长度小于等于y的线段。假设改线段大于等于x。
              则循环继续进行,否则跳出循环,输出No
    */
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    #include <iostream>
    #include <set>
    using namespace std;
    typedef long long LL;
    pair <pair<LL,LL>,int>p[200005];
    set<pair<LL,int> >mp;
    set<pair<LL,int> >::iterator k;
    int s[200005],n,m;
    
    int main()
    {
        LL u,v,x,y;
        while(~scanf("%d%d",&n,&m))
        {
            for(int i=0; i<n; i++)
            {
                scanf("%I64d%I64d",&x,&y);
                if(i>0)
                {
                    p[i]=make_pair(make_pair(v-x,u-y),i);
                    ///printf("%d->%I64d %I64d
    ",i,p[i].first.first,p[i].first.second);
                }
                u=x;
                v=y;
            }
            mp.clear();
            for(int i=1; i<=m; i++)
            {
                scanf("%I64d",&x);
                mp.insert(make_pair(x,i));
            }
            sort(p+1,p+n);
            int flag=1;
            for(int i=1; i<n; i++)
            {
                x=-p[i].first.first;
                y=-p[i].first.second;
                //printf("%I64d %I64d
    ",x,y);
                k=mp.lower_bound(make_pair(y,1<<30));
                if(k==mp.begin())
                {
                    puts("No");
                    flag=0;
                    break;
                }
                k--;
                if(k->first<x)
                {
                    puts("No");
                    flag=0;
                    break;
                }
                s[p[i].second]=k->second;
                mp.erase(k);
            }
            if(flag)
            {
                puts("Yes");
                for(int i=1; i<n; i++)
                {
                    printf(i==n-1?"%d
    ":"%d ",s[i]);
                }
            }
        }
        return 0;
    }
    


  • 相关阅读:
    kubernetes入门之kube-proxy实现原理
    kubernetes源码阅读及编译
    docker的网络-Container network interface(CNI)与Container network model(CNM)
    kubernetes入门之skydns
    浅析flannel与docker结合的机制和原理
    kubernetes入门之快速部署
    python并发获取snmp信息及性能测试
    Facebook开源的基于SQL的操作系统检测和监控框架:osquery daemon详解
    Facebook开源的基于SQL的操作系统检测和监控框架:osquery Table详解
    视频工具类产品是个什么玩意,产品经理怎么构思一款视频工具类产品
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6707935.html
Copyright © 2020-2023  润新知