HDOJ2579,BFS(三维数组标记)
三维数组对于我这个萌萌的新手来说真是酷酷的,帅到不行,,,
三维数组前面还看到空间的哪一题HDOJ1240,这一题时间上的标记,更酷了!!!
不说废话了,贴一发代码;
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string.h>
#include <math.h>
#include<stdlib.h>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
#define N 110
char a[N][N];
int flag[N][N][110];
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
struct asd{
int x,y,step;
}now,ne;
queue<asd>q;
int r,c,k;
int ax,ay,bx,by;
void bfs()
{
int i,s;
memset(flag,0,sizeof(flag));
while(!q.empty())
q.pop();
now.x=ax;
now.y=ay;
now.step=0;
flag[ax][ay][0]=1;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
for(i=0;i<4;i++)
{
int aa=dx[i]+now.x;
int bb=dy[i]+now.y;
if(a[aa][bb]=='G')
{
printf("%d\n",now.step+1);
return;
}
s=(now.step+1)%k;
if(aa<0||aa>=r||bb<0||bb>=c||flag[aa][bb][s]||(a[aa][bb]=='#'&&s))
continue;
ne.x=aa;
ne.y=bb;
ne.step=now.step+1;
flag[aa][bb][s]=1;
q.push(ne);
}
}
printf("Please give me another chance!\n");
}
int main()
{
int i,j,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&r,&c,&k);
for(i=0;i<r;i++)
{
scanf("%s",a[i]);
}
int f1,f2;
f1=f2=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]=='Y')
{
ax=i;
ay=j;
f2=1;
}
if(a[i][j]=='G')
{
bx=i;
by=j;
f1=1;
}
if(f1&&f2)
break;
}
if(f1&&f2)
break;
}
bfs();
}
return 0;
}
HDOJ2579,BFS(三维数组标记)的更多相关文章
- hdu 5433 Xiao Ming climbing(bfs+三维标记)
Problem Description Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can ...
- hdoj 2579 Dating with girls(2)【三重数组标记去重】
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Clumsy Keke【模拟+三维数组】
Clumsy Keke 题目链接(点击) Problem Description Keke is currently studying engineering drawing courses, and ...
- Jni :三维数组处理方法 ,以整形三维数组为例 C++实现
本文原创,转载请注明地址:http://www.cnblogs.com/baokang/p/4982846.html 关于Jni的基本使用方法,请参阅:Java 调用 C++ (Java 调用 dll ...
- C语言三维数组分解
很多人在学习C的时候,感觉三维数组很难想象,而且不理解深度是什么?做了一个图,帮大家分解一下 ...
- Java 一维数组 二维数组 三维数组
二维数组包含一位数组 三维数组就是在二维数组的基础上,再加一层.把二维数组看做是一维数组就可以了,按照上述理解类推. 下面是 一维 二维 三维数组例子 一维数组: int[] array1 ...
- 三维数组——与 宝玉QQ群讨论交流之二
宝玉 12:27:35 这几天看了大部分大家交的作业,发现一个主要问题还是卡在对三维数组的理解上,之前把三维数组类比成三维空间可能会造成误导 宝玉 12:27:45 其实鞠老师解释的很好: 三维数组 ...
- c# 基础之数组(包含三维数组)
public enum ChessType { White = , None=, Black=, } class Program { static void Main(string[] args) { ...
- php三维数组变二维数组
<?php $result = Array(0 => Array(0 => Array(bid => 41,brealname => 'we教官',cid => 4 ...
随机推荐
- WPF 后台Render线程崩溃, Exception from HRESULT: 0x88980406
近期遇到一个问题.窗口在Loaded同一时候Resize会出现黑屏或者直接崩溃, 调查发现是WPF后端的Render线程渲染UI到DirectX时崩溃. 硬件环境:WES7 + .Net4.0 关于W ...
- WPF自定义Popup和弹出菜单
Popup: <StackPanel Grid.Column="0" Grid.Row="6" Orientation="Horizontal& ...
- redis文档翻译_LRU缓存
Using Redis as an LRU cache使用Redis作为LRU缓存 出处:http://blog.csdn.net/column/details/redisbanli.html Whe ...
- difference between http get and post
1 用get的地方 在浏览器中输入url直接访问资源时,用get.get是通过url传参的. 2 用post的地方 2.1 url长度超限时 post是将参数放在http body中的,因此对参数的长 ...
- Sleeping Beauty,摘自iOS应用Snow White and more stories
Once upon a time, there lived a king and queen. 从前,有个国王和王后. They had a beautiful daughter. 他们有一个漂亮的女 ...
- ckeditor html标签的class 等attribute属性都被屏蔽啦,替换成空的解决方案
ckeditor 模块中自定义class 在ckeditor模块中,编辑内容时, 在源码中填写<div class="myclass">some content< ...
- JavaProject和IProject
由 IProject 项目得到 Java 项目的方式: IJavaProject javaPoject = JavaCore.create(IProject); 由 IJavaProject 得到 I ...
- Machine Learning No.1: Linear regression with one variable
1. hypothsis 2. cost function: 3. Goal: 4. Gradient descent algorithm repeat until convergence { (fo ...
- Windows下配置PHPUnit(pear已弃用,使用phpunit.phar)
一.配置PHPUnit 首先到PHPUnit官网(点此进入)下载相应的版本.php 5.5及以下版本请使用PHPUnit 4.8.得到 .phar 文件,并把名字改为 phpunit.phar . 把 ...
- xmlToEntity or entityToXML 工作笔记
最近工作中调用接口,返回报文是String,取值不方便,需要转换为实体,回来自己简单写了个demo,基本上可以满足工作需求. 除了下面代码外,还要创建对应的实体. package yh.test.t1 ...