hdu1240 bfs 水题
思路:水题,直接搜
#include "map"
#include "queue"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#define abs(x) x > 0 ? x : -x
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b using namespace std; int z2,x2,y2,n;
int d[][]= {{,,},{,,},{,,-},{,-,},{,,},{-,,}};
bool Map[][][],vis[][][]; struct Node{
int zz,xx,yy;
int step;
}; void Bfs(int z,int x,int y)
{
memset(vis,,sizeof(vis));
queue<Node>Q;
Node now,next; now.zz = z;
now.xx = x;
now.yy = y;
now.step = ;
vis[z][x][y] = ; Q.push(now); while(!Q.empty())
{
now = Q.front();
Q.pop(); if(now.zz==z2 && now.xx==x2 && now.yy==y2)
{
printf("%d %d\n",n,now.step);
return;
} for(int i=; i<; i++)
{
next.zz = now.zz + d[i][];
next.xx = now.xx + d[i][];
next.yy = now.yy + d[i][];
next.step = now.step + ; if(Map[next.zz][next.xx][next.yy] && !vis[next.zz][next.xx][next.yy])
{
vis[next.zz][next.xx][next.yy] = ;
Q.push(next);
}
}
}
printf("NO ROUTE\n");
} int main()
{
int x1,y1,z1,i,j,k;
char s[],c;
while(~scanf("%s%d",s,&n))
{
memset(Map,,sizeof(Map));
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
getchar();
for(k=; k<=n; k++)
{
scanf("%c",&c);
if(c=='O')
Map[i][j][k] = ;
if(c=='X')
Map[i][j][k] = ;
}
} scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
z1+=,x1+=,y1+=,z2+=,x2+=,y2+=;
getchar();
gets(s); Bfs(z1,x1,y1);
}
return ;
}
hdu1240 bfs 水题的更多相关文章
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...
- nyoj--523--亡命逃窜(BFS水题)
亡命逃窜 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...
- POJ3287(BFS水题)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- POJ 3126 Prime Path bfs, 水题 难度:0
题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...
- codeforces 811 D. Vladik and Favorite Game(bfs水题)
题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子, ...
- CYJian的水题大赛
实在没忍住就去打比赛了然后一耗就是一天 最后Rank19还是挺好的(要不是乐多赛不然炸飞),这是唯一一套在Luogu上号称水题大赛的而实际上真的是水题大赛的比赛 好了我们开始看题 T1 八百标兵奔北坡 ...
- hihocoder 1322 - 树结构判定 - [hiho一下161周][模板题/水题]
题目链接:http://hihocoder.com/problemset/problem/1322 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个包含 N 个顶 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
随机推荐
- 基于能量收集的智能家居-2013国家级大学生创业实践项目申报_商业计划书_V0.2
SmartHome项目商业计划 基于能量收集的 免电池无线智能家居系统 IA-SmartHome团队 2012.12 l 基于无线的智能家居解决方案,节省施工成本: l 基于能 ...
- 命令模式/command模式/行为型模式
举个栗子 指挥官向士兵下达命令,士兵执行 实现代码如下: class Soldier { public void exe() { System.out.println("执行命令" ...
- JS对Array进行自定制排序
JS对Array进行自定制排序,简单的做一个记录,代码如下所示: //Test function function myFunction(){ var myArr = new Array(); var ...
- 使用yum来安装或卸载CentOS图形界面包
命令行模式安装图形界面 yum grouplist 检查已安装的组 yum groupinstall "X Window System" yum groupinstall &quo ...
- MPAndroidChart饼图属性及相关设置
公司最近在做统计功能,所以用到了饼图,在网上查了一些资料最终决定使用MPAndroidChart,使用起来非常方便,还有一些问题通过各种查找,终于解决...废话不多说,先看下效果图: 布局文件: &l ...
- 彻底搞懂Html5本地存储技术(一)
一.H5之前客户端本地存储的实现 1. cookies cookies的应用比较广泛,但有以下几个问题: (1)每次http请求头上会带着,浪费资源 (2)每个域名客户端只能存储4K大小 (3)会造成 ...
- zoj 3469 Food Delivery 区间dp + 提前计算费用
Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...
- 怎么提高Jquery性能
很久没有关注jQuery了,最近重新看了一下,看到一些不错的文章,转来坐一下笔记. 其内容和一些新提供的方法还是很多有值得学习的地方. 1. 使用最新版本的jQuery jQuery的版本更新很快,你 ...
- 使用Spring发送邮件
http://www.oschina.net/code/snippet_253813_36503
- JavaScript类型转换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...