$des$

实现一个bfs

$sol$

写了一个双向bfs

#include <bits/stdc++.h>

using namespace std;

#define Rep(i, a, b) for(int i = a; i <= b; i ++)

#define gc getchar()
inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
} const int N = ;
const int xd[] = {-, -, -, -, , , , };
const int yd[] = {-, -, , , , , -, -}; int Lim = ;
int vis[N][N], bel[N][N];
int n;
int Bfs_time;
queue<pair <int, int> > Q; inline int Work(int sx, int sy, int tx, int ty) {
if(sx == tx && sy == ty) return ;
memset(vis, , sizeof vis);
memset(bel, , sizeof bel);
while(!Q.empty()) Q.pop();
Q.push(make_pair(sx, sy));
Q.push(make_pair(tx, ty));
bel[sx][sy] = , bel[tx][ty] = ;
vis[tx][ty] = ;
while(!Q.empty()) {
pair <int, int> tp = Q.front();
Q.pop();
int px = tp.first, py = tp.second;
Rep(i, , ) {
int nx = px + xd[i], ny = py + yd[i];
if(bel[nx][ny] == bel[px][py] || nx < || nx > Lim || ny < || ny > Lim) continue;
if(vis[nx][ny]) return vis[nx][ny] + vis[px][py];
vis[nx][ny] = vis[px][py] + ;
bel[nx][ny] = bel[px][py];
Q.push(make_pair(nx, ny));
}
}
} int main() {
n = read();
while(n --) {
Lim = read();
cout << Work(read(), read(), read(), read()) << "\n";
}
return ;
}

75: libreoj #10028 双向宽搜的更多相关文章

  1. [NOIP2002] 字串变换 宽搜+深度优化

    这道题硬是让我用STL水过.......而且题解里说的什么双向宽搜,交替扩展............... 这道题反正,STL用就用吧,但是状态数可以卡到千亿级别,因为这个东西是阶乘扩展的,然后我们发 ...

  2. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  3. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  4. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  5. POJ1426 Find The Multiple (宽搜思想)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24768   Accepted: 102 ...

  6. Colorado Potato Beetle(CF的某道) & 鬼畜宽搜

    题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...

  7. 双向广搜 POJ 3126 Prime Path

      POJ 3126  Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16204   Accepted ...

  8. 双向广搜 codevs 3060 抓住那头奶牛

    codevs 3060 抓住那头奶牛 USACO  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold   题目描述 Description 农夫约翰被告知一头逃跑奶牛 ...

  9. 双向广搜+hash+康托展开 codevs 1225 八数码难题

    codevs 1225 八数码难题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description Yours和zero在研究A*启 ...

随机推荐

  1. MNIST机器学习入门(一)

    一.简介 首先介绍MNIST 数据集.如图1-1 所示, MNIST 数据集主要由一些手写数字的图片和相应的标签组成,图片一共有10 类,分别对应从0-9 ,共10 个阿拉伯数字. 原始的MNIST ...

  2. 阿里云主机centos7系统创建SWAP区,并启动挂载(适合无SWAP区虚拟化平台)

    以root用户登录建立交换区文件: fallocate -l 2G /swapfile /swapfile //赋予仅root用户的权限,确保安全 mkswap /swapfile swapon /s ...

  3. vim打开多个文件、同时显示多个文件、在文件之间切换

    打开多个文件: 1.vim还没有启动的时候: 在终端里输入  vim file1 file2 ... filen便可以打开所有想要打开的文件 2.vim已经启动 输入 :open file 可以再打开 ...

  4. Vert.x 异步访问数据库 MySQL

    Vert.x提供异步访问数据库的API,数据库操作是一个耗时操作,使用传统的同步模型,容易阻塞线程,导致整体性能下降,因此我们对于数据库操作,需要使用Vert.x提供的异步API. Vert.x提供的 ...

  5. Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口

    HttpURLConnection是JDK自身提供的网络类,不需要引入额外的jar包.文中所使用到的软件版本:Java 1.8.0_191. 1.服务端 参见Java调用Http接口(1)--编写服务 ...

  6. Pod和Namespace的基本介绍

    namespace资源名称空间 删除namespace资源会级联删除其所包含的所有其它资源对象    名称空间仅仅只是用来限制资源名称的作用域      并不能实现Pod的通信隔离 在名称空间下操作s ...

  7. Nginx 反向代理Tomcat服务器获取真实IP问题

    1.nginx.conf 配置 修改 Server location配置 增加 proxy_set_header X-Real-IP $remote_addr; #保留代理之前的真实客户端ip pro ...

  8. day 10 预科

    目录 IPO 编程 面向对象编程 类和对象 对象 类 定义类 定义对象 定义类语法 定义对象 (实例化对象) 定制对象独有特征 LeetCode检测机制 面向过程编程:面向(对着)-->过程(流 ...

  9. 使用awrsqrpt.sql查看执行计划demo

    SQL> @?/rdbms/admin/awrsqrpt.sql Current Instance ~~~~~~~~~~~~~~~~ DB Id DB Name Inst Num Instanc ...

  10. 判断CPU大小端示例代码

    #include <stdio.h> int checkCPU() { union w{ int a; char b; }c; c.a = ; ); } int main() { prin ...