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 读写文件中w与wt, r与rt的区别
w和wt是一们的,r和rt是一样的,t是默认参数,可以省略的,help(open)就能看到open的参数的详细说明. w,r,wt,rt都是python里面文件操作的模式.w是写模式,r是读模式.t是 ...
- charles 手机抓包 unknown
设置通配符即可 需要注意的点: 手机配置好电脑的服务器ip和端口号后,下载证书和安装好,然后电脑也需要安装证书.再配置可允许ssl 本地域名.
- 用Python实现随机森林算法,深度学习
用Python实现随机森林算法,深度学习 拥有高方差使得决策树(secision tress)在处理特定训练数据集时其结果显得相对脆弱.bagging(bootstrap aggregating 的缩 ...
- DNS服务器原理介绍(一)
DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串.通过主机名,最终 ...
- ACM题目————STL练习之求次数
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...
- pythoy的configparser模块
生成配置文件的模块 DEFAULT块,在以块为单位取块的值时,都会出现 import configparser config = configparser.ConfigParser() #相当于生成了 ...
- JWT(Json web token)认证详解
JWT(Json web token)认证详解 什么是JWT Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该to ...
- Android实验一(在Android Studio中创建项目和模拟器)
北京电子科技学院(BESTI) 实 验 报 告 课程:移动平台开发 班级:1592 姓名:苏泽楠 学号:20159207 成绩: 指导教师 ...
- Cron表达式详解和表达式的验证
本篇不算原创,因为主要内容来自网上的博客,所以给出我参考文章的链接. 本文cron表达式详解的大部分内容参考了[cron表达式详解]和Quartz使用总结.Cron表达式 这两篇文章. cron校验的 ...
- git源码阅读
https://github.com/git-for-windows/git/issues/1854 https://github.com/git-for-windows/git/pull/1902/ ...