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 ...
随机推荐
- Spotlight实时监控Windows Server 2008
Windows Server 2008作为服务器平台已逐渐被推广和应用,丰富的功能和良好的稳定性为其赢得了不错的口碑.但是和Windows Server 2003相比,其系统的自我监控功能并没有多大的 ...
- win 8.1 安装framework3.5
其实win8的iso上带着net 3.5的功能的,但是并没有随着系统安装二安装上去.所以只要你有跟你系统同个版本的iso文件,就可以实现不联网安装net3.5.首先把装载你的iso.Win8系统可以打 ...
- 面向对象之对象,作用域及this
object eg: var o = { a : 2, b : 3 }; console.log(o); console.log(typeof o); console.log(o.a.toFixed( ...
- 简单几何(直线求交点) POJ 2074 Line of Sight
题目传送门 题意:从一条马路(线段)看对面的房子(线段),问连续的能看到房子全部的最长区间 分析:自己的思路WA了:先对障碍物根据坐标排序,然后在相邻的障碍物的间隔找到区间,这样还要判断是否被其他障碍 ...
- 转:.NET获取当前方法名或调用此方法的方法名
Introduction Before .NET, we were always looking for a way to log current method name in a log file ...
- BZOJ2388 : 旅行规划
考虑分块,每块维护两个标记$ts,td$. 那么对于块中一个位置$i$,它的实际值为$i\times td+ts+v_i$. 修改的时候,对于整块,直接打标记,对于零散的暴力修改,然后重构凸壳,时间复 ...
- Lambda表达式可以被转换为委托类型
void Main() { //向Users类中增加两人; List<Users> user=new List<Users>{ new Users{ID=1,Name=&quo ...
- objective-c 条件运算符
条件运算符 val1!=0 ? val1:val2 等价于 val1?val2
- C# 取整
double a = 1.1478; Math.Celling(a): 向上取整,结果为2 Math.Float(a); 向下取整,结果为1 Math.Round(a,2); 保留两位小数的奇进偶舍 ...
- mysql中的comment用法
转自:http://wenku.baidu.com/view/2a54e7892cc58bd63186bd8f.html 在MySQL数据库中,字段或列的注释是用属性comment来添加. 创建新表的 ...