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 ...
随机推荐
- git commit规范化实践
最近从svn转到git进行代码版本控制,今天了解了git commit规范化的一些知识后,写此文章记录下配置过程. 环境 编辑器使用的是vscode,项目框架是vue3.0 规范化工具 规范化git ...
- 小白学python-day05(2)-列表及其操作
今天是day05(2),以下是学习总结 但行努力,莫问前程. --------------------------------------------------------------------- ...
- iis8 php-cgi.exe - FastCGI 进程意外退出 500错误解决办法
今天iis服务环境下的网站突然显示200错误php-cgi.exe - FastCGI 进程意外退出,昨天还好好的网站正常,这个问题一直偶尔出现几次,不是很频繁,但是偶尔会出现: 这是由于某些加载库加 ...
- 【JDK】JDK源码分析-TreeMap(1)
概述 前面数据结构与算法笔记对红黑树进行了分析,而 TreeMap 内部就是基于红黑树实现的.示意图: 它的查找.插入.删除操作的时间复杂度均为 O(logn). TreeMap 类的继承结构如下: ...
- 【NOI 2015】程序自动分析 并查集与离散化处理
题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,-代表程序中出现的变量,给定n个形如xi=xj或xi≠xj的变量 ...
- mule发布调用webservice
mule发布webservice 使用mule esb消息总线发布和调用webservice都非常精简,mule包装了所有操作,你只需要拖控件配置就可以,下面讲解mule发布: 1.下面是flow,h ...
- 基于JaCoCo的Android测试覆盖率统计(二)
> 本文章是我上一篇文章的升级版本,详见地址:https://www.cnblogs.com/xiaoluosun/p/7234606.html ## 为什么要做这个?1. 辛辛苦苦写了几百条测 ...
- ceph log机制
Log 是每个项目必须的,他是跟踪问题的最直接的依据.Ceph 也设计自己的log机制. 初始化启动log实例,启动log线程. _log = new ceph::log::Log(&_con ...
- kubernetes CRD开发指南
扩展kubernetes两个最常用最需要掌握的东西:自定义资源CRD 和 adminsion webhook, 本文教你如何十分钟掌握CRD开发. kubernetes允许用户自定义自己的资源对象,就 ...
- Python 使用k-means方法将列表中相似的句子聚为一类
由于今年暑假在学习一些自然语言处理的东西,发现网上对k-means的讲解不是很清楚,网上大多数代码只是将聚类结果以图片的形式呈现,而不是将聚类的结果表示出来,一下代码将老师给的代码和网上的代码结合了一 ...