POJ 1979 Red and Black
2015-07-19 21:22
288 查看
http://poj.org/problem?id=1979
//POJ 1979 Red and Black
#include<stdio.h>
#include<string.h>
#define N 25
int W,H;//列,行
int vis
;//标记已走过的
char map
;//储存矩形房间的瓷砖分布
int sum;//统计可行走黑色瓷砖数目
int main()
{
int i,j;
int x_start,y_start;//@的行,列
int search(int i,int j);
while(scanf("%d%d",&W,&H),W+H)
{
getchar();//吸收一个字符
sum=0;
memset(vis,0,sizeof(vis));
for(i=1;i<=H;i++)
{
for(j=1;j<=W;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='@')//标记@的行会和列
{
x_start=i;
y_start=j;
}
}
getchar();//吸收字符
}
search(x_start,y_start);//从@开始搜索
printf("%d\n",sum);
}
return 0;
}
int search(int i,int j)//搜索
{
if(i==0||i==H+1||j==0||j==W+1)//不能越界
return 0;
else if(map[i][j]=='#')
return 0;
else if(!vis[i][j])
{
sum++;
vis[i][j]=1;//标记走过的黑色瓷砖
search(i+1,j);//按上下左右的方式搜索
search(i-1,j);
search(i,j-1);
search(i,j+1);
}
return 0;
}
//POJ 1979 Red and Black
#include<stdio.h>
#include<string.h>
#define N 25
int W,H;//列,行
int vis
;//标记已走过的
char map
;//储存矩形房间的瓷砖分布
int sum;//统计可行走黑色瓷砖数目
int main()
{
int i,j;
int x_start,y_start;//@的行,列
int search(int i,int j);
while(scanf("%d%d",&W,&H),W+H)
{
getchar();//吸收一个字符
sum=0;
memset(vis,0,sizeof(vis));
for(i=1;i<=H;i++)
{
for(j=1;j<=W;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='@')//标记@的行会和列
{
x_start=i;
y_start=j;
}
}
getchar();//吸收字符
}
search(x_start,y_start);//从@开始搜索
printf("%d\n",sum);
}
return 0;
}
int search(int i,int j)//搜索
{
if(i==0||i==H+1||j==0||j==W+1)//不能越界
return 0;
else if(map[i][j]=='#')
return 0;
else if(!vis[i][j])
{
sum++;
vis[i][j]=1;//标记走过的黑色瓷砖
search(i+1,j);//按上下左右的方式搜索
search(i-1,j);
search(i,j-1);
search(i,j+1);
}
return 0;
}
相关文章推荐
- 自定义标签在IE6-8的困境
- 用WCAT进行IIS压力测试
- 词法分析器总结
- codeforces 555 C Case of Chocolate
- NSRunLoop扩展阅读
- hessian入门
- linux无线网卡驱动安装
- ZOJ 3230 Solving the Problems(数学 优先队列啊)
- C#泛型总结
- 欢迎使用CSDN-markdown编辑器
- 音乐touch ur soul
- 数组矩阵的顺时针输出
- 2015 HUAS Provincial Select Contest #1
- 欢迎使用CSDN-markdown编辑器
- .NET获取当前程序所在电脑的CPU和内存使用率
- git学习笔记
- git学习笔记
- Objective-C设计模式——原型Prototype(对象创建)
- HttpHandler简介
- 12100 Printer Queue(优先队列)