Codeforces 556D - Case of Fugitive
Posted Wisdom+.+
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 556D - Case of Fugitive相关的知识,希望对你有一定的参考价值。
思路:将桥长度放进二叉搜索树中(multiset),相邻两岛距离按上限排序,然后二分查找桥长度匹配并删除。
代码:
#include<bits/stdc++.h> using namespace std; #define ll long long const int N=2e5+5; struct node { ll x; ll y; int id; bool operator <(const node &a)const { return y<a.y; } }l[N],b[N]; struct Node { ll x; int id; bool operator <(const Node &a)const { return x<a.x; } }a[N]; int ans[N]; multiset<Node>ss; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,m; cin>>n>>m; cin>>b[0].x>>b[0].y; for(int i=1;i<n;i++) { cin>>b[i].x>>b[i].y; l[i-1].x=b[i].x-b[i-1].y; l[i-1].y=b[i].y-b[i-1].x; l[i-1].id=i; } for(int i=0;i<m;i++) { cin>>a[i].x; a[i].id=i+1; ss.insert(a[i]); } sort(l,l+n-1); for(int i=0;i<n-1;i++) { auto it=ss.lower_bound(Node{l[i].x,0}); if(it==ss.end()) { cout<<"No"<<endl; return 0; } if(it->x<=l[i].y) { ans[l[i].id]=it->id; ss.erase(it); } else { cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; for(int i=1;i<n-1;i++) cout<<ans[i]<<" "; cout<<ans[n-1]<<endl; return 0; }
以上是关于Codeforces 556D - Case of Fugitive的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces - 556C Case of Matryoshkas
CodeForces - 556C Case of Matryoshkas (水题)
CodeForces - 556A Case of the Zeros and Ones
Codeforces 555 B. Case of Fugitive
codeforces 555b//Case of Fugitive// Codeforces Round #310(Div. 1)