FZU 2235
中文题,题意略。
这个题点少坐标范围大,直接离散化后建图搞。
这个题目卡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的更多相关文章
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- FZU 2112 并查集、欧拉通路
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- ACM: FZU 2110 Star - 数学几何 - 水题
FZU 2110 Star Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Pr ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
随机推荐
- python模块导入-软件开发目录规范-01
模块 模块的基本概念 模块: # 一系列功能的结合体 模块的三种来源 """ 模块的三种来源 1.python解释器内置的模块(os.sys....) 2.第三方的别人写 ...
- 2015.11.27---Java
public class star{ public static void main(String[] args) { System.out.print("ha"); } }
- mac 下搭建安装 sass
一.安装系统需要的包 安装Xcode开发工具,它将帮你安装好 Unix 环境需要的开发包 打开 App Store,搜索 Xcode,第一个就是,对了,有4个多G,网速如果不大好,就请先厕所哭会儿吧, ...
- Spring Boot2(十五):Shiro记住我rememberMe、验证码Kaptcha
接着上次学习的<Spring Boot2(十二):手摸手教你搭建Shiro安全框架>,实现了Shiro的认证和授权.今天继续在这个基础上学习Shiro实现功能记住我rememberMe,以 ...
- 动手造轮子:基于 Redis 实现 EventBus
动手造轮子:基于 Redis 实现 EventBus Intro 上次我们造了一个简单的基于内存的 EventBus,但是如果要跨系统的话就不合适了,所以有了这篇基于 Redis 的 EventBus ...
- ASP.NET Core MVC 之局部视图(Partial Views)
1.什么是局部视图 局部视图是在其他视图中呈现的视图.通过执行局部视图生成的HTML输出呈现在调用视图中.与视图一样,局部视图使用 .cshtml 文件扩展名.当希望在不同视图之间共享网页的可重用部分 ...
- 读写properties文件
1. 读properties文件 Properties props = new Properties(); try { InputStream in = new FileInputStream(&qu ...
- Jenkins 配置 SpringBoot 自动构建部署
服务器版本 Linux version 3.10.0-957.12.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8 ...
- 本地NTP服务器与客户端配置
1. NTP 简介 NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在集群中,为了保证各节点之间的时间一致,我们通常需要配置本地的 NT ...
- Spring Cloud下基于OAUTH2+ZUUL认证授权的实现
Spring Cloud下基于OAUTH2认证授权的实现 在Spring Cloud需要使用OAUTH2来实现多个微服务的统一认证授权,通过向OAUTH服务发送某个类型的grant type进行集中认 ...