中文题,题意略。

这个题点少坐标范围大,直接离散化后建图搞。

这个题目卡vector,真是一脸懵逼。。。。。。。。。。。。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define maxn 100050
#define F 0x3f
#define INF 0x3f3f3f3f
using namespace std; struct Point{
int x,y;
Point(int a = ,int b = ){
x = a,y = b;
}
Point operator+ (const Point& p){
return Point(p.x + x,p.y + y);
}
bool operator< (const Point& p) const{
if(p.x != x) return x < p.x;
else return y < p.y;
}
bool operator == (const Point& p) const{
return (x == p.x) && (y == p.y);
}
};
struct Edge{
int to,nxt;
}; Edge edge[maxn<<];
int head[maxn];
Point p1,p2;
Point mov[] = {Point(,),Point(-,),Point(,),Point(,-),Point(,),Point(-,),Point(-,-),Point(,-)};
Point store[maxn];
int N,tail,cnt;
int dist[maxn]; int bfs(int s,int t){
memset(dist,F,sizeof(dist));
queue<int> que;
que.push(s);
dist[s] = ;
while(que.size()){
//printf("i cannot out\n");
int temp = que.front();
que.pop();
for(int i = head[temp];i != -;i = edge[i].nxt){
int v = edge[i].to;
//printf("i == %d\n",i);
if(dist[v] != INF) continue;
if( dist[v] > dist[temp] + ){
dist[v] = dist[temp] + ;
que.push(v);
}
}
}
return dist[t];
}
void add_e(int from,int to){
edge[cnt].to = to,edge[cnt].nxt = head[from],head[from] = cnt++;
}
void init(){
memset(head,-,sizeof(head));
cnt = tail = ;
} int main(){
while(scanf("%d%d%d%d",&p1.x,&p1.y,&p2.x,&p2.y) == ){
init();
scanf("%d",&N);
int ri,ai,bi;
store[tail++] = p1,store[tail++] = p2;
for(int i = ;i < N;++i){
scanf("%d%d%d",&ri,&ai,&bi);
for(int j = ai;j <= bi;++j){
store[tail++] = Point(ri,j);
}
}
sort(store,store + tail);
tail = unique(store,store + tail) - store;
for(int i = ;i < tail;++i){
int id1 = i + ;
//printf("from (%d,%d):\n",store[i].x,store[i].y);
for(int j = ;j < ;++j){
Point temp = store[i] + mov[j];
int id2 = lower_bound(store,store + tail,temp) - store + ;
if(!(store[id2 - ] == temp)) continue;
//printf("to (%d,%d)\n",temp.x,temp.y);
add_e(id1,id2);
}
}
int s = lower_bound(store,store + tail,p1) - store + ;
int t = lower_bound(store,store + tail,p2) - store + ;
int ans = bfs(s,t);
printf("%d\n",ans == INF ? - : ans);
}
return ;
}

FZU 2235的更多相关文章

  1. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  2. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  3. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  4. FZU 2112 并查集、欧拉通路

    原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...

  5. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  6. ACM: FZU 2112 Tickets - 欧拉回路 - 并查集

     FZU 2112 Tickets Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u P ...

  7. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  8. ACM: FZU 2110 Star - 数学几何 - 水题

     FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Pr ...

  9. FZU 2150 Fire Game

    Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

随机推荐

  1. TensorFlow(1)-基础知识点总结

    1. tensorflow简介 Tensorflow 是 google 开源的机器学习工具,在2015年11月其实现正式开源,开源协议Apache 2.0. Tensorflow采用数据流图(data ...

  2. springboot - 登录+静态资源访问+国际化

    1.项目目录结构 2.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  3. jquery3和layui冲突导,致使用layui.layer.full弹出全屏iframe窗口时高度152px问题

    项目中使用的jquery版本是jquery-3.2.1,在使用layui弹出全屏iframe窗口时,iframe窗口顶部总是出现一个152px高的滚动窗口无法实现真正全屏,代码如下: <!DOC ...

  4. Clock Crossing Adapter传输效率分析 (Latency增加,传输效率降低)

    原创By DeeZeng [ Intel FPGA笔记 ] 在用Nios II测试 DDR3时候发现一个现象 (测试为:写全片,读全片+比对) 用单独的PLL产生时钟(200MHz)驱动 Nios I ...

  5. .net core(c#)拟合圆测试

    说明 很多时候,我们需要运动物体的转弯半径去描述其机器性能.但在大多数的现实条件下,我们只能够获取到运动物体的 GPS 位置点集,并不能直接得到转弯半径或者圆心位置.为此,我们可以利用拟合圆的方式得到 ...

  6. java课堂 动手动脑2

    1.编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数 Modulus=231-1=int.MaxValue, Multiplier=75=16807. C=0 当显示过231-2个数 ...

  7. 后端基于方法的权限控制--Spirng-Security

    后端基于方法的权限控制--Spirng-Security 默认情况下, Spring Security 并不启用方法级的安全管控. 启用方法级的管控后, 可以针对不同的方法通过注解设置不同的访问条件: ...

  8. PythonDay04

    ## 第四章 ### 今日内容 - 列表- 元组- range ### 列表 列表相比于字符串,不仅可以储存不同的数据类型,而且可以储存大量数据,是一种可变的数据类型 64位python的限制是 11 ...

  9. ssm访问不了后台

    最近整理ssm,写完demo案例,无论如何都访问不了后台,百度了好多,终于解决了问题所在 先看页面信息: 因为一直报404错误,一直找路径是不是弄错了,或配置文件弄错了,仅仅这个配置文件都看了无数遍, ...

  10. eclipse项目导入idea jdk版本不一致😵

    在导入eclipse项目到idea过程中遇到 Imported project refers to unkonwn jdks JavaSE-1.8 解决方法: file --> Project ...