【编程练习】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语言开发过多线程,我只知 ...
随机推荐
- [LSGDOJ1822]书架 Splay
题目描述 Sally有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. Sally在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一 ...
- ●BOZJ 4456 [Zjoi2016]旅行者
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4456 题解: 分治好题.大致做法如下:对于一开始的矩形区域,过较长边的中点把矩形区域分为两个 ...
- bzoj1858[Scoi2010]序列操作 线段树
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 3079 Solved: 1475[Submit][Statu ...
- cookie读取、写入、删除
需求:用户访问页面之后出现弹框,点击关闭之后24小时内不会再出现.实现:cookie首先温习一点cookie的知识,明确以下几点:什么是cookie?cookie 是存储于访问者的计算机中的变量.每当 ...
- 修复 Ubuntu 14.04 的系统设置残缺问题
sudo apt-get install ubuntu-desktop
- C语言关闭日志文件时忘了将日志文件全局变量指针置为NULL
C语言写了一个write_log函数以写日志,写了一个close_log_file函数以关闭日志,声明了一个日志文件全局变量文件指针plogFile. write_log中首先判断plogFile是否 ...
- ES6(类)
类的概念 1.基本定义 2.继承 继承如何传递参数?(super) 定义自己属性的时候调用 this 一定要在 super 之后(在继承关系中,子类的构造函数如果用 super 传递参数的过程中,su ...
- Go 语言多维数组
Go 语言支持多维数组,以下为常用的多维数组声明方式: var variable_name [SIZE1][SIZE2]...[SIZEN] variable_type 以下实例声明了三维的整型数组: ...
- 基于Python预测股价
▌实现预测的Stocker工具 Stocker是一款用于探索股票情况的Python工具.一旦我们安装了所需的库(查看文档),我们可以在脚本的同一文件夹中启动一个Jupyter Notebook,并导入 ...
- Jmeter(二)_基础元件
测试计划(Test Plan) 它用来描述一个测试方案,包含与本次性能测试所有相关的功能.也就说本次测试的所有内容是于基于一个计划的. "函数测试模式"复选框,如果被选择,它会使J ...