POJ 1979 Red and Black
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 21
struct node
{
int x;
int y;
};
int n,m,g[MAXN][MAXN];
bool vis[MAXN][MAXN];
int x[]={,-,,};
int y[]={,,,-};
int bfs(int sx,int sy)
{
int ans = ;
node temp;
temp.x = sx;
temp.y = sy;
vis[sx][sy] = true;
queue<node> q;
q.push(temp);
while(!q.empty())
{
temp = q.front();
q.pop();
//cout<<temp.x<<' '<<temp.y<<endl;
ans++;
for(int i=;i<;i++)
{
int tx = temp.x + x[i];
int ty = temp.y + y[i];
if((tx>=&&ty>=&&tx<m&&ty<n)&&!vis[tx][ty]&&g[tx][ty]=='.')
{
vis[tx][ty] = true;
node nn;
nn.x = tx;
nn.y = ty;
q.push(nn);
}
}
}
return ans;
}
int main()
{
while(scanf("%d%d",&n,&m))
{
getchar();
if(n+m==) break;
int sx,sy;
memset(g,,sizeof(g));
memset(vis,false,sizeof(vis));
for(int i=;i<m;i++)
{
for(int j=;j<n;j++)
{
scanf("%c",&g[i][j]);
if(g[i][j]=='@')
{
sx = i;
sy = j;
}
}
getchar();
}
cout<<bfs(sx,sy)<<endl;
}
return ;
}
POJ 1979 Red and Black的更多相关文章
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- POJ 1979 Red and Black (zoj 2165) DFS
传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
- HDOJ 1312 (POJ 1979) Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black (DFS)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black 四方向棋盘搜索
Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 50913 Accepted: 27001 D ...
随机推荐
- conversations.im
最后在即时消息 https://conversations.im/ https://github.com/chrisballinger/ 对话是Android 4.0的Jabber / XMPP客户 ...
- Ionic2系列-将beta升级到RC1
国庆节前Ionic2发布了RC0版本,已经接近正式版了,前不久Angular2和TypeScript2也已经发布了正式版.详情请参考官方博客: http://blog.ionic.io/announc ...
- WinForm拖动没有标题栏窗体的方法
建立窗体的名称修改为:Form_HoverTree 文后附有源码下载. 主要代码: Point _HoverTreePosition; public Form_HoverTree() { Initia ...
- svn+teamcity+YouTrack+Upsource搭建—写给明天工作室的小伙伴
首先解释下概念: SVN:Subversion的简称,版本控制系统.采用集中式管理(本地只保留服务器仓储的副本,想要把代码交到服务器或者看提交记录.差异对比就必须得有网络连接) Teamcity:可持 ...
- javascript操作系统检测
function detectOS() { var sUserAgent = navigator.userAgent;console.log(sUserAgent); var isWin = (nav ...
- 集成shareSDK错误总结(新浪微博)
错误1. . 以上错误是由于没有添加-ObjC的原因,在targets->Build Setting ->Other Linker Flags中添加-ObjC 添加方法如下 错误2 授权回 ...
- Android 如何有效的解决内存泄漏的问题
前言:最近在研究Handler的知识,其中涉及到一个问题,如何避免Handler带来的内存溢出问题.在网上找了很多资料,有很多都是互相抄的,没有实际的作用. 本文的内存泄漏检测工具是:LeakCana ...
- MVP解析
一套可以直接复制使用的MVP框架 通过对MVP设计模式学习,对MVP也有了一个初步的认识,以登录Login模块为例,封装MVP如下: package com.example.administrator ...
- C#接口的显示和隐式实现
早上骑车上班走到半路发现手机忘带了,这年代兜里没装一分现金,吃饭都要刷手机,上班时间无聊了不能玩手机更是大问题,所以果断掉头拿手机.取完手机刚出门看这天阴沉沉的貌似要下雨,没雨衣,骑车又不能打伞,上次 ...
- 信息系统实践手记6-JS调用Flex的性能问题一例
说明:信息系统实践手记系列是系笔者在平时研发中先后遇到的大小的问题,也许朴实和细微,但往往却是经常遇到的问题.笔者对其中比较典型的加以收集,描述,归纳和分享. 摘要:此文描述了笔者接触过的部分信息系统 ...