556D - Case of Fugitive

思路:将桥长度放进二叉搜索树中(multiset),相邻两岛距离按上限排序,然后二分查找桥长度匹配并删除。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+;
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();
int n,m;
cin>>n>>m;
cin>>b[].x>>b[].y;
for(int i=;i<n;i++)
{
cin>>b[i].x>>b[i].y;
l[i-].x=b[i].x-b[i-].y;
l[i-].y=b[i].y-b[i-].x;
l[i-].id=i;
}
for(int i=;i<m;i++)
{
cin>>a[i].x;
a[i].id=i+;
ss.insert(a[i]);
}
sort(l,l+n-);
for(int i=;i<n-;i++)
{
auto it=ss.lower_bound(Node{l[i].x,});
if(it==ss.end())
{
cout<<"No"<<endl;
return ;
}
if(it->x<=l[i].y)
{
ans[l[i].id]=it->id;
ss.erase(it);
}
else
{
cout<<"No"<<endl;
return ;
}
}
cout<<"Yes"<<endl;
for(int i=;i<n-;i++)
cout<<ans[i]<<" ";
cout<<ans[n-]<<endl;
return ;
}

Codeforces 556D - Case of Fugitive的更多相关文章

  1. CodeForces - 556D Case of Fugitive (贪心+排序)

    Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet ...

  2. codeforces 555B Case of Fugitive

    题目连接: http://codeforces.com/problemset/problem/555/B 题目大意: 有n个岛屿(岛屿在一列上,可以看做是线性的,用来描述岛屿位置的是起点与终点),m个 ...

  3. codeforces 555b//Case of Fugitive// Codeforces Round #310(Div. 1)

    题意:有n-1个缝隙,在上面搭桥,每个缝隙有个ll,rr值,ll<=长度<=rr的才能搭上去.求一种搭桥组合. 经典问题,应列入acm必背300题中.属于那种不可能自己想得出来的题.将二元 ...

  4. 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/p ...

  5. Codeforces 555 B. Case of Fugitive

    \(>Codeforces \space 555 B. Case of Fugitive<\) 题目大意 : 有 \(n\) 个岛屿有序排列在一条线上,第 \(i\) 个岛屿的左端点为 \ ...

  6. Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)

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

  7. CodeForces - 556D

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

  8. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  9. Codeforces 556D Restructuring Company

    传送门 D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. !!【通达信】求教:如何对A股的所有股票按照某个选股指标的某个参数排序? - 理想论坛 中国人气最旺的股票论坛

    http://www.55188.com/thread-7152852-1-1.html .401进入指标排序,然后占右键把指标更改为MACD即可.(注意401前投资面有一个点!)

  2. QPixmap 显示大小

    size picSize(600,400); //将pixmap缩放成picSize大小然后保存在scaledPixmap中 按比例缩放: QPixmap scaledPixmap = pixmap. ...

  3. linux中的各种$号 位置参数变量

    位置参数变量   $n   #/bin/bash echo $0(代表命令本身); echo $1; (代表第几个参数) echo $2;   [root@LocalWeb01 ~]# ./1.sh ...

  4. 通俗理解RxJS(一)

    自学 Rx 快有一个周了, 它非常适合处理复杂的异步场景.结合自己所学,决定写系列教程. 我认为, Rx 中强大的地方在于两处 管道思想,通过管道,我们订阅了数据的来源,并在数据源更新时响应 . 强大 ...

  5. 《Bilateral Multi-Perspective Matching for Natural Language Sentences》(句子匹配)

    问题: Natural language sentence matching (NLSM),自然语言句子匹配,是指比较两个句子并判断句子间关系,是许多任务的一项基本技术.针对NLSM任务,目前有两种流 ...

  6. Intermediate Python for Data Science learning 1 - Basic plots with matplotlib

    Basic plots with matplotlib from:https://campus.datacamp.com/courses/intermediate-python-for-data-sc ...

  7. Linux其他: GitBash

    git bash是Windows下的命令行工具 安装后在任何一个文件夹下右键GitBash,打开一个窗口,ssh root@xx.xxx.xxx.xx登陆到服务器,输入yes,和登陆密码可以使用敲命令 ...

  8. 20145316许心远《网络对抗》MSF基础应用

    20145316许心远<网络对抗>MSF基础应用 实验后回答问题 用自己的话解释什么是exploit,payload,encode. exploit:顾名思义就是攻击嘛,因为是个动词,所以 ...

  9. python3.4学习笔记(二) 类型判断,异常处理,终止程序

    python3.4学习笔记(二) 类型判断,异常处理,终止程序,实例代码: #idle中按F5可以运行代码 #引入外部模块 import xxx #random模块,randint(开始数,结束数) ...

  10. 20145109竺文君、20145106石晟荣 java实验三

    重构的概念:重构(Refactoring)就是通过调整程序代码改善软件的质量.性能,使其程序的设计模式和架构更趋合理,提高软件的扩展性和维护性. 首先由zwj在<git.oschina.net& ...