FZU2235 国王的出游 水题
因为只有1e5个点,所以直接离散化bfs就好
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const int mod=;
pii p[N],tmp;
int dx[]={-,-,-,,,,,};
int dy[]={-,,,-,,-,,};
int head[N],tot,d[N],cnt;
struct Edge{
int v,next;
}edge[*N];
void add(int u,int v){
edge[tot].v=v;
edge[tot].next=head[u];
head[u]=tot++;
}
queue<int>q;
int get(int s,int t){
while(!q.empty())q.pop();
memset(d,-,sizeof(d));
d[s]=;q.push(s);
while(!q.empty()){
int u=q.front();
q.pop();
if(u==t)return d[t];
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
if(d[v]==-)d[v]=d[u]+,q.push(v);
}
}
return -;
}
int main(){
int x1,x2,y1,y2,n,s,t;
while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
scanf("%d",&n);
memset(head,-,sizeof(head)),cnt=tot=;
for(int i=;i<=n;++i){
int x,l,r;
scanf("%d%d%d",&x,&l,&r);
for(int j=l;j<=r;++j)
++cnt,p[cnt].first=x,p[cnt].second=j;
}
sort(p+,p++cnt);
cnt=unique(p+,p++cnt)-p-;
for(int i=;i<=cnt;++i){
for(int j=;j<;++j){
tmp.first=p[i].first+dx[j];
tmp.second=p[i].second+dy[j];
int pos=lower_bound(p+,p++cnt,tmp)-p;
if(pos==cnt+||p[pos].first!=tmp.first||p[pos].second!=tmp.second)
continue;
add(i,pos);
}
}
tmp.first=x1,tmp.second=y1;
s=lower_bound(p+,p++cnt,tmp)-p;
tmp.first=x2,tmp.second=y2;
t=lower_bound(p+,p++cnt,tmp)-p;
printf("%d\n",get(s,t));
}
return ;
}
FZU2235 国王的出游 水题的更多相关文章
- 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)
http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- ACM水题
ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...
随机推荐
- rsync+inotity
rsync默认端口:873xinetd默认服务 inotify参数详解inotifywait-r:递归-q:只打印事件-m:始终监听事件--excludei:排除--timefmt:时间格式--for ...
- Memcached 缓存个体,对象,泛型,表
转自 :http://www.cnblogs.com/panshengqiang/p/3605599.html 下面是两位大牛关于Memcached的介绍:大家可以看看 http://zhoufoxc ...
- Oracle datafile特殊字符处理
1.发现数据库的数据文件有特殊字符: 2.尝试在sqlplus下用将tablespace offline后修改 SQL> alter tablespace WST_DATA rename dat ...
- Python 的格式化字符串format函数
阅读mattkang在csdn中的博客<飘逸的python - 增强的格式化字符串format函数>所做笔记 自从python2.6开始,新增了一种格式化字符串的函数str.format( ...
- Ubuntu 下部署asp.net运行环境
在Ubuntu下部署asp.net运行环境,网上教程很多,基本都是编译Mono源码,然后安装jexus.但是可能是我最近RP不太好,编译Mono源码一直都是失败,无奈之下只好找另外的方法安装了. 网上 ...
- codeforces Codeforces Round #345 (Div. 1) C. Table Compression 排序+并查集
C. Table Compression Little Petya is now fond of data compression algorithms. He has already studied ...
- Kinetic使用注意点--animation
new Animation(func, layers) 参数: func:每一帧都会调用一次此函数.此函数接收一个包含四个元素的参数对象,时间单位均为毫秒. { timeDiff:"上一帧和 ...
- AppExtention - today
声明: 本文转自王巍 WWDC 2014 Session笔记 - iOS 通知中心扩展制作入门 本文是我的 WWDC 2014 笔记 中的一篇,涉及的 Session 有 Creating Exten ...
- ios更改UITabBarController背景以及选中背景图片的方法
一.背景图片 1.5.0以上版本 UIImage *image = [UIImage imageNamed:@"system_tabbar_bg.png"]; [ ...
- python 图片上添加数字源代码
最近因工作需要,需要在图片上添加数字,查询了资料,自己写了一个方法,并进行了测试,由于代码用到了PIL库,需要下载安装,下载地址:http://www.pythonware.com/products/ ...