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 ...
随机推荐
- 代码静态检查Eclipse插件:SonarLint插件离线安装
Eclipse Version: Oxygen.3a Release (4.7.3a)Myeclipse版本: 10.7 SonarLint 插件离线安装包:org.sonarlint.eclipse ...
- Python 在序列上跟踪索引和值
内置的enumerate() 函数可以很好的解决这个问题 >>> my_list = ['a', 'b', 'c'] >>> for idx, val in enu ...
- react脚手架构建工程
https://blog.csdn.net/qtfying/article/details/78665664 第二步:安装less包: https://segmentfault.com/a/11900 ...
- centos 网卡配置
地址:/etc/sysconfig/network-scripts vi /etc/sysconfig/network-scripts/ifcfg-eth0 1.固定ip配置 DEVICE=eth0 ...
- Lombok让pojo变得更优雅
Lombok 采取注解的形式,标记在pojo上面,在编译后,自动生成相应的方法,像get.set.构造方法等都可以注解一键生成. 引入jar包: <dependency> <grou ...
- noip 瑞士轮 - 归并
背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分冗长 ...
- Win32程序支持命令行参数的做法(转载)
转载:http://www.cnblogs.com/lanzhi/p/6470406.html 转载:http://blog.csdn.net/kelsel/article/details/52759 ...
- C# 获取当前IIS请求地址
using System;using System.Collections.Generic;using System.Linq;using System.Web; /// <summary> ...
- Wireshark过滤总结
Wireshark提供了两种过滤器:捕获过滤器:在抓包之前就设定好过滤条件,然后只抓取符合条件的数据包.显示过滤器:在已捕获的数据包集合中设置过滤条件,隐藏不想显示的数据包,只显示符合条件的数据包.需 ...
- JavaScript new return 类的实例化
new初始化方法 简单没有return的就不写了 function Person() { this.name="hongda"; ; return "fffffff&qu ...