poj1979
#include<stdio.h>
int map[4][4]={'.','.','.','.',
'#','.','.','.',
'.','#','.','.',
'#','.','.','@'};
int mov1[4]={0,0,1,-1};
int mov2[4]={1,-1,0,0};
typedef struct node
{
int x;
int y;
}node;
node dui[100];
int tou=0;
int wei=1;
void bfs()
{
int nx;
int ny;
dui[tou].x=3;
dui[tou].y=3;
while(tou<wei)
{
for(int i=0;i<4;i++)
{
nx=dui[tou].x+mov1[i];
ny=dui[tou].y+mov2[i];
if(nx>=0&&nx<4&&ny>=0&&ny<4&&map[nx][ny]=='.')
{
dui[wei].x=nx;
dui[wei].y=ny;
map[nx][ny]='#';
wei++;
}
}
tou++;
}
}
int main()
{
bfs();
printf("%d",tou);
return 0;
}
poj1979的更多相关文章
- POJ1979 Red and Black (简单DFS)
POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- poj1979 Red And Black(DFS)
题目链接 http://poj.org/problem?id=1979 思路 floodfill问题,使用dfs解决 代码 #include <iostream> #include < ...
- 《挑战程序设计竞赛》2.1 深度优先搜索 POJ2386 POJ1979 AOJ0118 AOJ0033 POJ3009
POJ2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25366 Accepted: ...
- HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) 解题报告
题目链接:pid=1312" target="_blank">HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) Red ...
- POJ1979(Red and Black)--FloodFill
题目在这里 题目意思是这样的,一个人起始位置在 '@' 处,他在途中能到达的地方为 ' . ' 而 '#' 是障碍物,他不能到达. 问途中他所有能到达的 '.'的数量是多少 ? ...
- POJ-1979 Red and Black(DFS)
题目链接:http://poj.org/problem?id=1979 深度优先搜索非递归写法 #include <cstdio> #include <stack> using ...
- POJ1979 Red and Black
速刷一道DFS Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- Poj1979 Red and Black (DFS)
Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 47466 Accepted: 25523 D ...
- poj-1979 red and black(搜索)
Time limit1000 ms Memory limit30000 kB There is a rectangular room, covered with square tiles. Each ...
随机推荐
- poj 1019
懂了 题意是给一串 1 12 123 1234 12345 123456 ....这样的数字问第 i个数字是多少 Sample Input 2 8 3 Sample Output 2 2 #inclu ...
- 对学长所谓“改变世界的游戏”《shield star》的运行感想-毛宇部分(完整版本请参考团队博客)
对于学长项目<shield star>的思考和看法: Ryan Mao ((毛宇) 110616-11061171 试用了一下学长黄杨等人开发的<shield star>游戏 ...
- linux su和sudo命令的区别(转)
一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比如我们以普通用户beinan登录的,但要添加用户任务,执行useradd ,beinan用 ...
- selector选择器
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="ht ...
- 【log4j2 加载配置文件】 加载配置文件的三种方法
log4j 2读取的配置文件可以分为三类:src下的配置文件.绝对路径的配置文件.相对路径的配置文件. package com.herman.test; import java.io.File; im ...
- Android 在资源文件(res/strings.xml)定义一维数组,间接定义二维数组
经常我们会在资源文件(res/strings.xml)定义字符串,一维数组,那定义二维数组?直接定义二维数组没找到,可以间接定义. 其实很简单,看过用过一次就可以记住了,一维数组估计大家经常用到,但是 ...
- Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 使用C#导出MSSQL表数据Insert语句,支持所有MSSQL列属性
在正文开始之前,我们先看一下MSSQL的两张系统表sys.objects . syscolumnsMSDN中 sys.objects表的定义:在数据库中创建的每个用户定义的架构作用域内的对象在该表中均 ...
- C#控制鼠标位置
It is not possible using the .NET BCL. However if you really want it you can use native SetCursorPos ...
- it's hard to say
Ew,it's hard to begin.In fact I don't know what to say either.So here is a sad story.First of all ,m ...