POJ 1111
#include<iostream>
#define MAXN 30
using namespace std; char _m[MAXN][MAXN];
bool mark[MAXN][MAXN];
int dir_f[][] = {,,,-,,,-,};
int dir_l[][] = {,,,-,-,,-,-};
int ans;
int r;
int c;
void DFS(int g_i,int g_j);
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int j;
int g_r;
int g_c;
while(cin>>r>>c>>g_r>>g_c)
{
memset(mark,false,sizeof(mark));
if(!r && !c && !g_r && !g_c)
{
break;
}
for(i = ; i < r; ++ i)
{
for(j = ; j < c; ++ j)
{
cin>>_m[i][j];
}
}
-- g_r;
-- g_c;
ans = ;
mark[g_r][g_c] = true;
DFS(g_r,g_c);
cout<<ans<<endl;
}
} void DFS(int g_i,int g_j)
{
// cout<<g_i<<" "<<g_j<<endl;
int i;
int j;
int tem_i;
int tem_j;
for(i = ; i < ; ++ i)
{
if(dir_f[i][] + g_i >= && dir_f[i][] + g_i < r && dir_f[i][] + g_j>= && dir_f[i][] + g_j < c && _m[dir_f[i][] + g_i][dir_f[i][] + g_j] == 'X' && !mark[dir_f[i][] + g_i][dir_f[i][] + g_j])
{
mark[dir_f[i][] + g_i][dir_f[i][] + g_j] = true;
DFS(dir_f[i][] + g_i,dir_f[i][] + g_j);
}
else if(!mark[dir_f[i][] + g_i][dir_f[i][] + g_j])
{
++ ans;
}
}
for(i = ; i < ; ++ i)
{
tem_i = dir_l[i][] + g_i;
tem_j = dir_l[i][] + g_j;
if(tem_i >= && tem_i < r && tem_j >= && tem_j < c && _m[tem_i][tem_j] == 'X' && !mark[tem_i][tem_j])
{
mark[tem_i][tem_j] = true;
DFS(tem_i,tem_j);
}
}
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1111的更多相关文章
- [POJ]1111 Image Perimeters
Description Technicians in a pathology lab analyze digitized images of slides. Objects on a slide ar ...
- POJ 1111(数字很吉利嘛) 简单BFS
Image Perimeters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8594 Accepted: 5145 Desc ...
- poj1111 DFS
J - 搜索 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit I ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- POJ 3216 最小路径覆盖+floyd
Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6646 Accepted: 178 ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ 1700 Crossing River (贪心)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...
随机推荐
- 2018.10.15 loj#6010. 「网络流 24 题」数字梯形(费用流)
传送门 费用流经典题. 按照题目要求建边. 为了方便我将所有格子拆点,三种情况下容量分别为111,infinfinf,infinfinf,费用都为validi,jval_{id_{i,j}}valid ...
- UML学习归纳整理
转载自:https://www.jianshu.com/p/83afa19c5096 写在前面 之前在学校比较系统的学习过统一建模语言UML,但长时间没使用遗忘了许多,最近因工作需要,所以对UML重新 ...
- 批量远程执行shell命令工具
使用示例(使用了默认用户root,和默认端口号22): ./mooon_ssh --h=192.168.4.1,192.168.4.2 -P=password -c='cat /etc/hosts' ...
- SPFA穿越虫洞——负权回路得判断
poj3259 题目大意:穿越虫洞可以回到过去(时间--)所以能不能让时间倒流呢,就是判断有没有负权回路这次尝试用SPFA算法,也可以复习一下链式前向星 准备工作,队列q,spfa算法得有点就在于这个 ...
- [php] try - catch exceptiong handler
//http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warningOne possibility is to set your ...
- Delphi for iOS开发指南(6):在iOS应用程序中使用ComboBox组件来从列表中选择某一项
http://blog.csdn.net/delphiteacher/article/details/8924110 Delphi for iOS开发指南(6):在iOS应用程序中使用ComboBox ...
- Redis键迁移
Redis键迁移 在使用Redis的过程中,很多时候我们会遇到需要进行键迁移的问题,需要将指定Redis中的指定数据迁移到其他Redis当中,键迁移有三种方法,我们来进行一一介绍. 一.move ...
- EasyUi TreeGrid/DataGrid getChecked BUG
问题描述 步骤一,选中左边树一个节点,然后出现相应的数据,选中进行保存.如,我选中了前4个节点,上图: 步骤二,我再选tree中第二个节点,进行相应的选中和取消选中treegrid中的节点,并保存. ...
- SVG系列教程:SVG简介与嵌入HTML页面的方式
地址:http://www.w3cplus.com/html5/svg-introduction-and-embedded-html-page.html 随着技术向前的推进,SVG相关的讨论也越渐频繁 ...
- .Net中XML,JSON的几种处理方式
一.XML: 1.基本了解: xml,Extensible markup language可扩展标记语言,用于数据的传输或保存,特点,格式非常整齐数据清晰明了,并且任何语言都内置了xml分析引擎, 不 ...