[CF310]D. Case of Fugitive

題意:
給出n個線段,在n個線段之間搭橋,給出m個橋的長度,假如滿足條件
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.
,問最後可以連接所有的線段嗎?是的話輸出線段所對應的橋的編號。

分析:
數據量比較大,雖然題意很簡單,但是要想一些辦法降低複雜度。這個數據量二分可以nlogn可以處理,那這裏就用了set來處理,二分就用了lower_bound,另外題一點,pair

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility> 
#include<stack>
#include <algorithm>
#define read freopen("q.in","r",stdin)
#define LL long long
#define maxn 200005
using namespace std;

set <pair<pair<LL,LL>, int> > s;
multiset<pair<LL,LL> > k;
int res[maxn];
int main()
{ //'std::set<std::pair<std::pair<long long int, long long int>, int> >::iterator' has no member named 'first'
    LL n,m,x,y,a,b;
    int i,j;
    std::ios::sync_with_stdio(false);
    cin>>n>>m;

    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(i>0)s.insert(make_pair(make_pair(y-a,x-b),i));
        a=x;b=y;
    }
    for(i=1;i<=m;i++)
    {
        cin>>x;
        k.insert(make_pair(x,i));
    }
    for(set<pair<pair<LL,LL>, int> >:: iterator it =s.begin();it!=s.end();it++)
    {
        multiset<pair<LL,LL> > :: iterator  j=k.lower_bound(make_pair(it->first.second,-1));
        if(j==k.end() || j->first>it->first.first) 
        {
            cout<<"No"<<endl;
            return 0;
        }
        res[it->second]=j->second;
        k.erase(j);
    }
    cout<<"Yes"<<endl;
    for(i=1;i<n;i++)cout<<res[i]<<" ";
    cout<<endl;
}

ps:覺得對STL不熟。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章