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: ...
随机推荐
- Lua脚本之语法基础快速入门
要 1.基本数据类型 2.Lua中的常用语句结构以及函数 3.Lua中的常用语句结构介绍 4.Lua中的库函数 目录[-] 一.基本数据类型 二.Lua中的常用语句结构以及函数 1.Lua中的常用语句 ...
- 排序算法FOUR:堆排序HeapSort
/** *堆排序思路:O(nlogn) * 用最大堆,传入一个数组,先用数组建堆,维护堆的性质 * 再把第一个数与堆最后一个数调换,因为第一个数是最大的 * 把堆的大小减小一 * 再 在堆的大小上维护 ...
- Python3 IO
在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘,所以,读写文件就是请求操作系统打开一个文件对象(通常称为文件描述符),然后,通过操作系统提供的接口从这个文件对象中 ...
- tp数据表字段缓存
在维护一个tp写的项目,因为需要在产品表product中增加了一个字段status,但是不论如何就是无法给status赋值,查了资料才发现,原来是tp的数据表字段缓存在搞鬼. 在runtime> ...
- 推荐一个优秀的前端框架——Bootstrap
Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.Bootstra ...
- Distributed R
R语言的分布式目前有这几个产品: (A)RHadoop:对hadoop族系的产品,其中提供了以下的组件 A.1 rhdfs 浏览读取增加修改hdfs上面的文件数据: A.2 rhbase 浏览读取增 ...
- 使用pdb调试python
python pdb调试 python -m pdb myscript.py #注意这会重启myscript.py,这样启动的话,代码每一行都是一个节点 也可以在程序中这么设置断点: import p ...
- 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 ...
- poj 1830 开关问题
开关问题 题意:给n(0 < n < 29)开关的初始和最终状态(01表示),以及开关之间的关联关系(关联关系是单向的输入a b表示a->b),问有几种方式得到最终的状态.否则输出字 ...
- SQL中子查询为聚合函数时的优化
测试数据:create table test1 as select * from dba_objects where rownum<=10000;--10000条记录create table t ...