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 ...
随机推荐
- 主成分分析(PCA)学习笔记
这两天学习了吴恩达老师机器学习中的主成分分析法(Principal Component Analysis, PCA),PCA是一种常用的降维方法.这里对PCA算法做一个小笔记,并利用python完成对 ...
- python 星号*使用方法
1.乘号 2.表示倍数 def T(msg,time=1): print((msg+',,')*time) >>>T('hi',3) hi,,hi,,hi 3.单个星号* --1-- ...
- Linux命令: 在线练习网址
1.https://www.tutorialspoint.com/unix_terminal_online.php 2.从 这里 https://www.tutorialspoint.com/inde ...
- Python Web学习笔记之WebSocket 通信过程与实现
一.什么是 WebSocket ? WebSocket 是一种标准协议,用于在客户端和服务端之间进行双向数据传输.但它跟 HTTP 没什么关系,它是基于 TCP 的一种独立实现. 以前客户端想知道服务 ...
- bzoj1704 / P2882 [USACO07MAR]面对正确的方式Face The Right Way
P2882 [USACO07MAR]面对正确的方式Face The Right Way $n<=5000$?枚举翻转长度,顺序模拟就ok了 对于每次翻转,我们可以利用差分的思想,再搞搞前缀和. ...
- c++的各种类型转换方式
const_cast 用于去掉const属性,把const类型的指针变为非const类型的指针,如:const int *fun(int x,int y){} int *ptr=const_cast& ...
- JavaScript:正则表达式 问号
问号 1.?表示重复前面内容的0次或一次(但尽可能多重复) var reg=/abc?/g; var str="abcdabcaba"; console.log(str.match ...
- Slf4j+LogBack使用参考
博文参考: 最简例子:https://blog.csdn.net/johnson_moon/article/details/77532583 Web中配置:https://blog.csdn.net/ ...
- 手机常用meta标签-有注释
<!-- 设置字体编码 --> <meta charset="UTF-8"> <!-- 视图窗口,移动端特属的标签. --> <meta ...
- UVa 11212 编辑书稿(dfs+IDA*)
https://vjudge.net/problem/UVA-11212 题意:给出n个自然段组成的文章,将他们排列成1,2...,n.每次只能剪切一段连续的自然段,粘贴时按照顺序粘贴. 思路:状态空 ...