[CF310]D. Case of Fugitive
2015-06-30 13:12
316 查看
题意:
给出n个线段,在n个线段之间搭桥,给出m个桥的长度,假如满足条件
To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length a can be placed between the i-th and the (i + 1)-th islads, if there are such coordinates of x and y, that li ≤ x ≤ ri, li + 1 ≤ y ≤ ri + 1 and y - x = a.
,问最后可以连接所有的线段吗?是的话输出线段所对应的桥的编号。
分析:
数据量比较大,虽然题意很简单,但是要想一些办法降低复杂度。这个数据量二分可以nlogn可以处理,那这里就用了set来处理,二分就用了lower_bound,另外题一点,pair
ps:觉得对STL不熟。。。
给出n个线段,在n个线段之间搭桥,给出m个桥的长度,假如满足条件
To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length a can be placed between the i-th and the (i + 1)-th islads, if there are such coordinates of x and y, that li ≤ x ≤ ri, li + 1 ≤ y ≤ ri + 1 and y - x = a.
,问最后可以连接所有的线段吗?是的话输出线段所对应的桥的编号。
分析:
数据量比较大,虽然题意很简单,但是要想一些办法降低复杂度。这个数据量二分可以nlogn可以处理,那这里就用了set来处理,二分就用了lower_bound,另外题一点,pair
[code]#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <vector> #include <map> #include <set> #include <utility> #include<stack> #include <algorithm> #define read freopen("q.in","r",stdin) #define LL long long #define maxn 200005 using namespace std; set <pair<pair<LL,LL>, int> > s; multiset<pair<LL,LL> > k; int res[maxn]; int main() { //'std::set<std::pair<std::pair<long long int, long long int>, int> >::iterator' has no member named 'first' LL n,m,x,y,a,b; int i,j; std::ios::sync_with_stdio(false); cin>>n>>m; for(i=0;i<n;i++) { cin>>x>>y; if(i>0)s.insert(make_pair(make_pair(y-a,x-b),i)); a=x;b=y; } for(i=1;i<=m;i++) { cin>>x; k.insert(make_pair(x,i)); } for(set<pair<pair<LL,LL>, int> >:: iterator it =s.begin();it!=s.end();it++) { multiset<pair<LL,LL> > :: iterator j=k.lower_bound(make_pair(it->first.second,-1)); if(j==k.end() || j->first>it->first.first) { cout<<"No"<<endl; return 0; } res[it->second]=j->second; k.erase(j); } cout<<"Yes"<<endl; for(i=1;i<n;i++)cout<<res[i]<<" "; cout<<endl; }
ps:觉得对STL不熟。。。
相关文章推荐
- UITableView的cell的分割线位置
- 【MFC】基于对话框的键盘响应
- c++回调函数 callback
- 电容在电路中各种作用的基本常识
- VS2013下对项目进行单元测试
- 网页字体介绍以及网页常用字体设置
- Linux驱动修炼之道-RTC子系统框架与源码分析
- 01 引子
- .NET程序的性能要领和优化建议
- Nhibernate基础
- svn cleanup
- C++笔试题第一波
- error: two or more data types in declaration specifiers原因及解决方法 [转]
- 冒泡排序优化
- 红帽发力云分析,发布一系列新产品
- Linux下解压tar.xz格式压缩文件
- WPF入门教程系列九——布局之DockPanel与ViewBox(四)
- 线程学习第一课--线程同步
- T-Sql 函数,替换字段内的 html 标签
- golang、beego初探