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. SSH无密码登录:只需两个简单步骤 (Linux)

    最后更新 2017年4月8日 分类 最新文章 服务器安全 标签 RSA SSH Key 非对称加密 如果你管理一台Linux服务器,那么你就会知道每次SSH登录时或者使用scp复制文件时都要输入密码是 ...

  2. asp.net onclientclick事件刷新页面问题解决

      做网页经常要和JavaScript打交道,经常要用JavaScript做一些客户端的验证,但是如果我们的按钮用的是HTML控件的话,验证通过后无法调用后台代码,如果用服务器端控件,验证不通过有要刷 ...

  3. Eclipse 启动项目错误:class not found

    其中,很可能的原因:项目存在编译错误,根本没有编译成功,没有生成class文件:可查看problems标签页查看具体错误.

  4. OS X 下动态库的引用

    foo.c #include <stdio.h> void foo(void) { printf("foo.\n"); } main.c #include <st ...

  5. Linux基础命令---chmod

    chmod 改变文件或者目录的权限,可以用数字或者字母来标识权限.在数字模式下:0,代表没有权限:1,代表可执行:2,代表可读:4,代表可写:多个权限可以相加.在字符模式下:x,代表执行:r,代表读: ...

  6. JMeter:全面的乱码解决方案

    中文乱码一直都是比较让人棘手的问题,我们在使用Jmeter的过程中,也会遇到中文乱码问题 接口:http://127.0.0.1:8090/test 这个接口有一个参数name,返回结果就是你传的na ...

  7. web前端----css选择器样式

    一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...

  8. ACM题目————区间覆盖问题

    题目描述 设x1 , x2,... , xn是实直线上的n个点.用固定长度的闭区间覆盖这n个点,至少需要多少个这样的固定长度闭区间?设计解此问题的有效算法,并证明算法的正确性.编程任务:对于给定的实直 ...

  9. pyDay5

    内容来自廖雪峰的官方网站 1.递归函数的优点是定义简单,逻辑清晰. 2.使用递归函数需要注意防止栈溢出. 3.在计算机中,函数调用是通过栈(stack)这种数据结构实现的,每当进入一个函数调用,栈就会 ...

  10. troubleshooting-sqoop mysql导入hive 报:GC overhead limit exceeded

    Halting due to Out Of Memory Error...18/09/13 21:42:17 INFO mapreduce.Job: Task Id : attempt_1536756 ...