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 ...
随机推荐
- C# 不同访问符的访问级别
public----成员可以由任何代码访问. private----成员只能由类中的代码访问(如果没有使用任何关键字,就默认使用这个关键字). internal----成员只能由定义它的项目(程序集) ...
- linux初学者-网络桥接篇
linux初学者-网络桥接篇 在网络的使用中,有时需要搭建网络桥来实现网络桥接.例如在一台主机上制作一台虚拟机,虚拟机是没有物理网卡的,这时虚拟机数据的发送和接收就需要通过主机上的物理网卡,需要主机的 ...
- 如何把一个jar包导入到eclipse中
- c&c服务器(command and control server)
远程命令和控制服务器,目标机器可以接收来自服务器的命令,从而达到服务器控制目标机器的目的.该方法常用于病毒木马控制被感染的机器.
- Selenium+java - Ajax浮动框处理
Ajax浮动框 我们常遇到的某些网站首页输入框,点击后显示的浮动下拉热点,如下图: 实际案例 模拟场景如下: hao123首页搜索输入框,单击搜索框,点击浮动框中的哪吒票房破30亿,单击后选项的文字内 ...
- java并发编程(十一)----(JUC原子类)基本类型介绍
上一节我们说到了基本原子类的简单介绍,这一节我们先来看一下基本类型: AtomicInteger, AtomicLong, AtomicBoolean.AtomicInteger和AtomicLong ...
- eclipse插件——maven
项目开发中遇到的问题 都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? 为什么在我的机器上可以正常打包,而配置管理员却打不出来? 项目组加入了新的人员,我要给他说明编译环境如何设 ...
- JavaWeb前端分页显示方法
在前端中我们总会遇到显示数据的问题 - 正常情况分页显示是必须的,这个时候我们不能仅仅在前端进行分页,在前端其实做起分页是很困难的,着就要求我们在后台拿数据的时候就要把分页数据准备好,在前端我们只需要 ...
- 关于Java虚拟机运行时数据区域的总结
Java虚拟机运行时数据区域 程序计数器(Program Counter) 程序计数器作为一个概念模型,这个是用来指示下一条需要执行的字节码指令在哪. Java的多线程实际上是通过线程轮转做到的,如果 ...
- 在canvas中使用其他HTML元素
做一个功能如下图,随机生成100个大小.颜色随机的小球.点击开始运动的时候,小球开始运动,然后点击停止运动的时候,小球停止运动. 点击旁边的白色或者黑色,则背景颜色变为相应的颜色. HTML部分: & ...