codeforces 555b//Case of Fugitive// Codeforces Round #310(Div. 1)
题意:有n-1个缝隙,在上面搭桥,每个缝隙有个ll,rr值,ll<=长度<=rr的才能搭上去。求一种搭桥组合。
经典问题,应列入acm必背300题中。属于那种不可能自己想得出来的题。将二元组[ll,rr]排序(ll相同时再rr),长度x排序(升序)。一个全局优先队列pq(rr小的顶部)。for循环,对每个x,将ll比它小的放入优先队列pq,如果pq仍为空,说明这块桥用不上,不为空,看top的rr是否大于x,如果大于,这块桥就能用上,并且给当前的top一定是可行的。
乱码:
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
const int SZ=2e5+,INF=0x7FFFFFFF;
typedef long long lon;
lon match[SZ]; struct nd{
lon ll,rr,id;
nd(lon a=,lon b=):ll(a),rr(b){}
}; bool cmp(nd &x,nd &y)
{
if(x.ll!=y.ll)return x.ll<y.ll;
else return x.rr<y.rr;
} struct ope{
const bool operator()(nd &x,nd &y)const
{
return x.rr>y.rr;
}
}; struct bn{
lon val,id;
bn(lon a=,lon b=):val(a),id(b){}
bool operator<(bn &other)
{
return val<other.val;
}
}; int main()
{
std::ios::sync_with_stdio();
lon n,m;
cin>>n>>m;
vector<nd> vct,src;
for(lon i=;i<n;++i)
{
nd tmp;
cin>>tmp.ll>>tmp.rr;
src.push_back(tmp);
}
for(lon i=;i<n;++i)
{
nd tmp(src[i].ll-src[i-].rr,src[i].rr-src[i-].ll);
tmp.id=i-;
vct.push_back(tmp);
}
sort(vct.begin(),vct.end(),cmp);
vector<bn> bge;
for(lon i=;i<m;++i)
{
lon tmp;
cin>>tmp;
bge.push_back(bn(tmp,i));
}
sort(bge.begin(),bge.end());
priority_queue<nd,vector<nd>,ope> pq;
vector<lon> res;
for(lon i=,j=;i<m;++i)
{
lon cur=bge[i].val;
for(;j<n-;++j)
{
if(vct[j].ll<=cur)
{
pq.push(vct[j]);
}
else break;
}
if(pq.empty())
{
continue;
}
nd top=pq.top();
if(top.rr<cur)
{
}
else
{
pq.pop();
match[top.id]=bge[i].id+;
}
}
bool ok=;
for(lon i=;i<n-;++i)
{
//cout<<"mt: "<<match[i]<<endl;
if(match[i]==)ok=;
}
if(ok)
{
cout<<"Yes"<<endl;
for(lon i=;i<n-;++i)
{
if(i)cout<<" ";
cout<<match[i];
}
cout<<endl;
}
else cout<<"No"<<endl;
return ;
}
codeforces 555b//Case of Fugitive// Codeforces Round #310(Div. 1)的更多相关文章
- codeforces 555B Case of Fugitive
题目连接: http://codeforces.com/problemset/problem/555/B 题目大意: 有n个岛屿(岛屿在一列上,可以看做是线性的,用来描述岛屿位置的是起点与终点),m个 ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 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 ...
- 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 ...
- Codeforces 556D - Case of Fugitive
556D - Case of Fugitive 思路:将桥长度放进二叉搜索树中(multiset),相邻两岛距离按上限排序,然后二分查找桥长度匹配并删除. 代码: #include<bits/s ...
- Codeforces Round #310 (Div. 1) C. Case of Chocolate set
C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
随机推荐
- python webdriver firefox 登录126邮箱,先添加联系人,然后进入首页发送邮件,带附件。
代码:#encoding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom ...
- IO(字节流)
1. 字节流类以InputStream 和 OutputStream为顶层类,他们都是抽象类(abstract) 2. 最重要的两种方法是read()和write(),它们分别对数据的字节进行读写.两 ...
- [转载]C#操作符??和?:
先看如下代码: string strParam = Request.Params["param"]; if ( strParam== null ) { strParam= ...
- 干货:Java并发编程系列之synchronized(一)
1. 使用方法 synchronized 是 java 中最常用的保证线程安全的方式,synchronized 的作用主要有三方面: 确保线程互斥的访问代码块,同一时刻只有一个方法可以进入到临界区 保 ...
- 01: MySql简介
MySQL其他篇 目录: 参考网站 1.1 数据库介绍 1.2 视图 1.3 触发器 1.4 事物 1.1 数据库介绍返回顶部 1.什么是数据库? 1. 数据库(Database)是按照数据结构来组织 ...
- CSS3实现小黄人动画
转载请注明出处,谢谢! 每次看到CSS3动画就心痒痒想试一下,记得一个多月前看了白树哥哥的一篇博客,突然开窍,于是拿他提供的demo试了一下,感觉很棒!下图为demo提供的动画帧设计稿. 自己也想说搞 ...
- 0xc0000005:读取位置时发生访问冲突
这是空指针,比如: A* a=NULL; a->fun();//会提示标题错误,因为a没有分配空间
- Https流程,openssl本地自建证书,抓包
HTTPS:超文本安全传输协议,和HTTP相比,多了一个SSL/TSL的认证过程,端口为443在http(超文本传输协议)基础上提出的一种安全的http协议,因此可以称为安全的超文本传输协议.http ...
- RabbitMQ延时任务
概念: 消息的TTL(Time To Live)消息的TTL就是消息的存活时间.RabbitMQ可以对队列和消息分别设置TTL.对队列设置就是队列没有消费者连着的保留时间,也可以对每一个单独的消息做单 ...
- html文件引用本地js文件出现跨域问题的解决方案
在本地做个小demo,很简单,一个html文件,一个js文件,在html文件中通过<script>标签引入js,但是出现了一个意想不到的问题:浏览器报错—— 一番折腾后,终于弄明白了:加载 ...