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 ...
随机推荐
- laravel框架session使用教程
laravel是一款php框架了,在使用laravel时会碰到session使用问题了,在使用过程中碰到一些问题与一些应用的例子. 用Laravel开发应用,把原有的代码copy过来,以前的代码ses ...
- Android ActionBar 一步一步分析 (转)
原文摘自:http://blog.csdn.net/android2me/article/details/8874846 1.Action Bar 介绍 我们能在应用中看见的actionbar一般就是 ...
- ITEYE中的读书笔记:重构其实就是持续改进
原文地址:http://hawkon.iteye.com/blog/2093338#bc2355877 前段时间同事参加ITEYE的试读有奖, 没想到得了个奖,拿到一本书.由于同事的推荐我也认真读了一 ...
- sql2005 将一列的多行内容拼接成一行
select ID, Name = ( stuff ( ( select ',' + Name from Table_1 where ID = a.ID for xml path('') ),1,1, ...
- ArduinoYun的电源插座
ArduinoYun的电源插座 Arduino Yun有两排插座,这些插座可以按类型分为三类:电源.数字IO和模拟输入.电源部分主要集中在如图1.7所示的部分本文选自Arduino Yun快速入门教程 ...
- [LintCode] Trapping rain water II
Given n x m non-negative integers representing an elevation map 2d where the area of each cell is 1 ...
- HazelCast 的内存管理原理
As it is said in the recent article "Google: Taming the Long Latency Tail - When More Machines ...
- C#二进制与字符串之间的相互转换
1 /// <summary> 2 /// 将字符串转成二进制 3 /// </summary> 4 /// <param name="s">& ...
- cocos2d ccitemimage
#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" class H ...
- sql 关联查询
SELECT mms_sample_datas.* from mms_sample_datas where mms_sample_datas.mms_id in ( SELECT mms_sample ...