【编程练习】poj1111
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8632 | Accepted: 5168 |
Description
objects.
The digitized slides will be represented by a rectangular grid of periods, '.', indicating empty space, and the capital letter 'X', indicating part of an object. Simple examples are
XX Grid 1 .XXX Grid 2 XX .XXX .XXX ...X ..X. X...
An X in a grid square indicates that the entire grid square, including its boundaries, lies in some object. The X in the center of the grid below is adjacent to the X in any of the 8 positions around it. The grid squares for any two adjacent X's overlap on
an edge or corner, so they are connected.
XXX XXX Central X and adjacent X's XXX
An object consists of the grid squares of all X's that can be linked to one another through a sequence of adjacent X's. In Grid 1, the whole grid is filled by one object. In Grid 2 there are two objects. One object contains only the lower left grid square.
The remaining X's belong to the other object.
The technician will always click on an X, selecting the object containing that X. The coordinates of the click are recorded. Rows and columns are numbered starting from 1 in the upper left hand corner. The technician could select the object in Grid 1 by clicking
on row 2 and column 2. The larger object in Grid 2 could be selected by clicking on row 2, column 3. The click could not be on row 4, column 3.
One useful statistic is the perimeter of the object. Assume each X corresponds to a square one unit on each side. Hence the object in Grid 1 has perimeter 8 (2 on each of four sides). The perimeter for the larger object in Grid 2 is illustrated in the figure
at the left. The length is 18.
Objects will not contain any totally enclosed holes, so the leftmost grid patterns shown below could NOT appear. The variations on the right could appear:
Impossible Possible XXXX XXXX XXXX XXXX X..X XXXX X... X... XX.X XXXX XX.X XX.X XXXX XXXX XXXX XX.X ..... ..... ..... ..... ..X.. ..X.. ..X.. ..X.. .X.X. .XXX. .X... ..... ..X.. ..X.. ..X.. ..X.. ..... ..... ..... .....
Input
consisting of '.' and 'X' characters.
The end of the input is indicated by a line containing four zeros. The numbers on any one line are separated by blanks. The grid rows contain no blanks.
Output
Sample Input
2 2 2 2
XX
XX
6 4 2 3
.XXX
.XXX
.XXX
...X
..X.
X...
5 6 1 3
.XXXX.
X....X
..XX.X
.X...X
..XXX.
7 7 2 6
XXXXXXX
XX...XX
X..X..X
X..X...
X..X..X
X.....X
XXXXXXX
7 7 4 4
XXXXXXX
XX...XX
X..X..X
X..X...
X..X..X
X.....X
XXXXXXX
0 0 0 0
Sample Output
8
18
40
48
8
http://blog.csdn.net/palqing/article/details/6262594
思路:搜索,过程中把该块上所有的X旁边有几个点是".",把所有的点旁边的"."数加起来就是总连长了。
#include<iostream>
#include<string.h>
using namespace std;
char Mp[30][30];
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
int DFS(int r,int c)
{
if(Mp[r][c]=='.'||Mp[r][c]=='n') return 0;
Mp[r][c]='n';
int sum=0;
for(int i=0;i!=4;i++)
sum+=(Mp[r+dir[i][0]][c+dir[i][1]]=='.');
for(int i=0;i!=8;i++)
sum+=DFS(r+dir[i][0],c+dir[i][1]);
return sum;
}
int main()
{
int row,col,r,c;
while(cin>>row>>col>>r>>c && row)
{
memset(Mp,'.',sizeof(Mp));
for(int i=1;i<=row;i++)
for(int j=1; j<=col;j++)
cin>>Mp[i][j];
cout<<DFS(r,c)<<endl;
}
}
【编程练习】poj1111的更多相关文章
- 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代
2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...
- 读书笔记:JavaScript DOM 编程艺术(第二版)
读完还是能学到很多的基础知识,这里记录下,方便回顾与及时查阅. 内容也有自己的一些补充. JavaScript DOM 编程艺术(第二版) 1.JavaScript简史 JavaScript由Nets ...
- [ 高并发]Java高并发编程系列第二篇--线程同步
高并发,听起来高大上的一个词汇,在身处于互联网潮的社会大趋势下,高并发赋予了更多的传奇色彩.首先,我们可以看到很多招聘中,会提到有高并发项目者优先.高并发,意味着,你的前雇主,有很大的业务层面的需求, ...
- C#异步编程(一)
异步编程简介 前言 本人学习.Net两年有余,是第一次写博客,虽然写的很认真,当毕竟是第一次,肯定会有很多不足之处, 希望大家照顾照顾新人,有错误之处可以指出来,我会虚心接受的. 何谓异步 与同步相对 ...
- UE4新手之编程指南
虚幻引擎4为程序员提供了两套工具集,可共同使用来加速开发的工作流程. 新的游戏类.Slate和Canvas用户接口元素以及编辑器功能可以使用C++语言来编写,并且在使用Visual Studio 或 ...
- C#与C++的发展历程第三 - C#5.0异步编程巅峰
系列文章目录 1. C#与C++的发展历程第一 - 由C#3.0起 2. C#与C++的发展历程第二 - C#4.0再接再厉 3. C#与C++的发展历程第三 - C#5.0异步编程的巅峰 C#5.0 ...
- 猫哥网络编程系列:HTTP PEM 万能调试法
注:本文内容较长且细节较多,建议先收藏再阅读,原文将在 Github 上维护与更新. 在 HTTP 接口开发与调试过程中,我们经常遇到以下类似的问题: 为什么本地环境接口可以调用成功,但放到手机上就跑 ...
- 关于如何提高Web服务端并发效率的异步编程技术
最近我研究技术的一个重点是java的多线程开发,在我早期学习java的时候,很多书上把java的多线程开发标榜为简单易用,这个简单易用是以C语言作为参照的,不过我也没有使用过C语言开发过多线程,我只知 ...
随机推荐
- 2015 多校联赛 ——HDU5335(Walk out)
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...
- 51Nod 1326 遥远的旅途
题目描述: 一个国家有N个城市,这些城市被标为0,1,2,...N-1.这些城市间连有M条道路,每条道路连接两个不同的城市,且道路都是双向的.一个小鹿喜欢在城市间沿着道路自由的穿梭,初始时小鹿在城市0 ...
- 【Bzoj 1835 基站选址】
基站选址的区间里隐藏着DP优化的机密…… 分析: 不论是做过乘积最大还是石子合并,或者是其他的入门级别的区间DP题目的人呐,大米并认为读题后就能够轻松得出一个简洁明了的Dp转移方程. ...
- Python Django rest framework
本节内容 Django rest framework 安装 Django rest framwwork 环境配置 简单举例说明 Django中使用 rest framework 1.1 安装 Djan ...
- 记一次sql优化——left join不走索引问题
sql一执行就卡住,然后就...杀进程了 看了一下表的大小 第一反应就是加索引,然后explain看了一下走什么索引了,结果很尴尬,三个表,只走了一个索引...一群人在那纠结为毛走不了索引. 无意间发 ...
- Java正则过滤
import java.util.regex.Matcher; import java.util.regex.Pattern; public class LongStringtonumber { pu ...
- pycharm和shell中的sys.path不一样
用pip安装了一个模块,在pycharm中不能调用,然后发现shell和pycharm中的sys.path不一样. 纳尼?还能不一样? 很明显左边的pycharm的sys.path中少了三个重要的路径 ...
- JavaScript正则表达式模式匹配(4)——使用exec返回数组、捕获性分组和非捕获性分组、嵌套分组
使用exec返回数组 var pattern=/^[a-z]+\s[0-9]{4}$/; var str='google 2012'; alert(pattern.exec(str)); //返回一个 ...
- 地址下拉框,需要js级联js
function area() { _url = "/ashx/DropDownControl.ashx"; _swType = "GetArea"; _z = ...
- Oracle中备份用户对象的两种方法
方法1: 执行步骤: exp userid=用户名/密码@数据库名 file=c:\emp.dmp 使用当前用户导出 exp userid=sys/sys@数据库名 file=c:\emp.dmp o ...