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 ...
随机推荐
- rest-frameword框架的基本组件
序列化 1.models部分 from django.db import models # Create your models here. class Book(models.Model): tit ...
- Ubuntu通过修改配置文件进行网络配置
Ubuntu系统进行网络配置有的时候用图形界面不起作用,这种情况下可以直接修改某些启动脚本或配置文件 Ubuntu系统进行网络配置涉及到几个配置文件1./etc/network/interfaces ...
- phpStudy集成环境apche+openssl配置本地https
OpenSSl windows环境搭建 网上各种文章都说需要下载多个工具,实际上只要一个程序就好,下载地址http://slproweb.com/products/Win32OpenSSL.html ...
- django第二次 (转自刘江)
除了我们前面说过的普通类型字段,Django还定义了一组关系类型字段,用来表示模型与模型之间的关系. 一.多对一(ForeignKey) 多对一的关系,通常被称为外键.外键字段类的定义如下: clas ...
- Appium自动化测试环境搭建
前言 Appium是一个开源的自动化测试框架,支持跨平台,支持多种编程语言,可用于原生,混合和移动web应用程序,使用webdriver驱动ios,android应用程序.那么为了学习app自动化测试 ...
- Linux零拷贝技术,看完这篇文章就懂了
本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复 「1024」 即可领取,欢迎大家关注,二维码文末可以扫. 本文讲解 ...
- react项目建立导入包问题总结
1.react和react-dom包 使用react开发网页的话,我们难免会下载两个包,一个是react,一个是react-dom,其中react是react的核心代码.react的核心思想是虚拟Do ...
- 阿里云nas使用记录
公司买了阿里云的nas服务用来共享存储,多个web服务器共同挂载同一个nas服务.挂载过程中出现如下报错 NAS报错: [root@BJ-SBC fs]# mount -t nfs 10.10.8.1 ...
- HTML5 第二章 列表和表格和媒体元素
列表: (1)什么是列表? 列表就是信息资源的一种展示形式. (2)无序列表: 语法: <ul> <li>第1项</li> <li>第2项</li ...
- python自动化测试框架unittest
对于刚学习python自动化测试的小伙伴来说,unittest是一个非常适合的框架: 通过unittest,可以管理测试用例的执行,自动生成简单的自动化测试报告: 首先我们尝试编写编写一个最简单的un ...