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. .apk等常用文件下载出现如果应下载文件,请添加 iis MIME 映射。

    在下载.apk文件时出现错误. HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. ...

  2. <Convolutional Neural Network for Paraphrase Identification>

    code:https://github.com/chantera/bicnn-mi Yin的这篇论文提出了一种叫Bi-CNN-MI的架构,其中Bi-CNN表示两个使用Siamese框架的CNN模型:M ...

  3. yii2--windows下composer安装

    //文件及存放目录 D:\php\php.exe D:\php\composer.phar //设置path(追加) ; D:\php //创建composer.bat文件 D:\php>ech ...

  4. fafu 1413

    叉积的运用 ,不断的用叉积去判断 最小的拼图, 刚开始对点进行排序,每个人的排序规则不同做法可能不同,我是按照点的x轴进行x轴相同用y小的在前面,然后每个点按照最下的点开始进行查找 每次从一个点出发然 ...

  5. python利用WMI监控windows状态如CPU、内存、硬盘

    安装pywin32库 下载地址: https://sourceforge.net/projects/pywin32/files%2Fpywin32/选择对应python版本的文件.下载后在window ...

  6. javascript中的console.log有什么作用?

    javascript中的console.log有什么作用? 主要是方便你调式javascript用的.你可以看到你在页面中输出的内容. 相比alert他的优点是:他能看到结构话的东西,如果是alert ...

  7. Python3 Selenium定位不到元素常见原因及解决办法

    Python3 Selenium定位不到元素常见原因及解决办法 一.问题描述 在做web应用的自动化测试时,定位元素是必不可少的,这个过程经常会碰到定位不到元素的情况: 报错信息: no such e ...

  8. rabbitmq架构简介(包括集群)

    总的来说,rabbitmq使用erlang语言编写,其架构类似于servlet容器运行servlet应用,底层是erlang VM.然后是erlang节点,上面是应用.如下所示: 每个MQ中运行的应用 ...

  9. html判断当前页面是否在iframe中/顶级document中

    在使用div+iframe布局的应用中,通常我们希望在session超时或者未登录访问时跳转到登录页面,默认情况下iframe中的页面无法直接覆盖父页面,因此需要在登录页面加载的时候判断一下当前是否为 ...

  10. 关于编译安装php

    之前也装过一次是nginx和php的, 这次也是... but, 不知道是不是版本的问题还是环境方面的影响, 导致之前的gd库是安装失败的, 所以上次安装zabbix也是失败的, 这次换了5.6.2版 ...