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 ...
随机推荐
- hdu-1026(bfs+优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意:输入n,m和一个n*m的矩阵, .表示通路: x表示墙: n表示有一个怪物,消灭它需要n个 ...
- 实现字符串函数,strlen(),strcpy(),strcmp(),strcat()
实现字符串函数,strlen(),strcpy(),strcmp(),strcat() #include<stdio.h> #include<stdlib.h> int my_ ...
- b3_trcd_EDCD_new
# -*- coding:utf-8 -*- import re year="17A" ss='./data/' filename = ss+'EDCD%s.txt'%year ' ...
- MOD13A1: MODIS/Terra Vegetation Indices 16-Day L3 Global 500 m SIN Grid V006
https://lpdaac.usgs.gov/node/838 Description The MOD13A1 Version 6 product provides a Vegetation Ind ...
- MessageBox的常见用法
一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口句柄, ...
- HDU1551&&HDU1064 Cable master 2017-05-11 17:50 38人阅读 评论(0) 收藏
Cable master Time Limit: ...
- codis服务部署前的操作及初始化
1.检查服务器ipv6模块是否打开,如果打开需要禁用ipv6,防止codis-dashbord连接zookeeper失败. 因为不确定codis-dashbord服务连接zookeeper使用ipv4 ...
- 8086汇编语言(1)虚拟机安装ms-dos 7.1
8086汇编语言(1)虚拟机安装ms-dos 7.1 文/玄魂 前言 在开始这一系列文章之前,我想先说下,对于古董级的8086汇编到底还以有没有学习的必要.这里我说下我要从8086开始学习,而不是从w ...
- 微软发布TFS 2018!
也许你还没来得及使用TFS 2017,今天,微软已经发布了TFS 2018的第一个版本(RC1). 与之前所有的候选版本一样,这是一个正式上线(微软成称为go-live)的TFS版本.如果你计划采纳T ...
- NET 读取Word文档信息
1.添加程序集引用:WindowsBase 2.添加nuget:DocumentFormat.OpenXml 3.代码: var wordPath = @"C:\xxx.docx" ...