zoukankan      html  css  js  c++  java
  • Codeforces Round #310 (Div. 1) B. Case of Fugitive set

    B. Case of Fugitive

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

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

    Description

    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 ≤ ri, li + 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 Input

    4 4
    1 4
    7 8
    9 10
    12 14
    4 5 3 8

    Sample Output

    Yes
    2 3 1

    HINT

    题意

    有一排岛,然后让你在m个桥中选n个,然后搭在这些岛上,让相邻的岛相连接,输出方案

    题解:

    一开始脑补的是跑最大流,然后想了想复杂度,还是贪心搞吧

    先把每个桥可以搭的区间找出来,然后排序,找到小于右端点的最大值

    然后就好了

    其中输出编号比较麻烦,我们pair就好了

    代码

    //qscqesze
    #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 unsigned 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 maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        int 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;
    }
    
    //**************************************************************************************
    
    set<pair<ll,int> >s;
    pair<pair<ll,ll>,int> br[maxn];
    pair<ll,ll> a[maxn];
    set<pair<ll,int> >::iterator it;
    int ans[maxn];
    int main()
    {
        int n=read(),m=read();
        for(int i=0;i<n;i++)
            cin>>a[i].first>>a[i].second;
        for(int i=0;i<n-1;i++)
            br[i]=make_pair(make_pair(a[i].second-a[i+1].first,a[i].first-a[i+1].second),i);
        for(int i=0;i<m;i++)
        {
            ll kiss;
            cin>>kiss;
            s.insert(make_pair(kiss,i));
        }
        sort(br,br+n-1);
        for(int i=0;i<n-1;i++)
        {
            ll l=-br[i].first.first,r=-br[i].first.second;
            it=s.lower_bound(make_pair(r,inf));
            if(it==s.begin())
                return puts("No");
            it--;
            if(it->first<l)
                return puts("No");
            ans[br[i].second]=it->second;
            s.erase(it);
        }
        puts("Yes");
        for(int i=0;i<n-1;i++)
            cout<<ans[i]+1<<" ";
    }
  • 相关阅读:
    Java 流(Stream)、文件(File)和IO
    归并排序(Java)
    TreeMap和TreeSet在排序时如何比较元素?Collections工具类中的sort()方法如何比较元素?
    动态规划—矩阵链乘法
    SQL Server 行列转换
    dropdownlist无刷新传值
    ASP.NET在主题中添加CSS文件
    asp.net网站后台退出后,点后退按钮仍能进,如何安全退出
    下拉框数据绑定两种方式
    win7安装IIS及将网站发布到IIS上
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4604999.html
Copyright © 2011-2022 走看看