题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414

CSUST:点击打开链接

Finding crosses

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 729    Accepted Submission(s): 411

Problem Description
The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in southern Peru. They were designated as a UNESCO World Heritage Site in 1994. The high, arid plateau stretches more than 80 kilometres (50 mi) between the towns of Nazca and Palpa
on the Pampas de Jumana about 400 km south of Lima. Although some local geoglyphs resemble Paracas motifs, scholars believe the Nazca Lines were created by the Nazca culture between 400 and 650 AD.[1] The hundreds of individual figures range in complexity
from simple lines to stylized hummingbirds, spiders, monkeys, fish, sharks, orcas, llamas, and lizards.



Above is the description of Nazca Lines from Wikipedia. Recently scientists found out that those lines form many crosses. Do those crosses have something to do with the Christian religion? Scientists are curious about this. But at first, they want to figure
out how many crosses are there. So they took a huge picture of Nazca area from the satellite, and they need you to write a program to count the crosses in the picture.



To simplify the problem, we assume that the picture is an N*N matrix made up of 'o' and '#', and some '#' can form a cross. Here we call three or more consecutive '#' (horizontal or vertical) as a "segment". 



The definition of a cross of width M is like this:



1) It's made up of a horizontal segment of length M and a vertical segment of length M.

2) The horizontal segment and the vertical segment overlap at their centers.

3) A cross must not have any adjacent '#'.

4) A cross's width is definitely odd and at least 3, so the above mentioned "centers" can't be ambiguous.

For example, there is a cross of width 3 in figure 1 and there are no cross in figure 2 ,3 and 4.








You may think you find a cross in the top 3 lines in figure 2.But it's not true because the cross you find has a adjacent '#' in the 4th line, so it can't be called a "cross". There is no cross in figure 3 and figure 4 because of the same reason.
 
Input
There are several test cases. 

In each test case:

The First line is a integer N, meaning that the picture is a N * N matrix ( 3<=N<=50) . 

Next N line is the matrix.

The input end with N = 0
 
Output
For each test case, output the number of crosses you find in a line.
 
Sample Input
4
oo#o
o###
oo#o
ooo#
4
oo#o
o###
oo#o
oo#o
5
oo#oo
oo#oo
#####
oo#oo
oo##o
6
ooo#oo
ooo##o
o#####
ooo#oo
ooo#oo
oooooo
0
 
Sample Output
1
0
0
0
 
Source
 
Recommend
liuyiding
 

题意:给你一个 n*n 的图 (3 <= n <= 50)

找出有多少个十字架,输出结果

十字架结构:由 "#" 构成,十字架周围不可以有 "#" 才满足条件

比如说这个图:有一个十字架,那么红色区域都不能够是 "#", 否则一个十字架也没有,输出 0 .

算法:等于没有算法,dfs 应该可以做,但是简单暴力枚举即可秒过。

PS:英文很吓人啊,比赛的时候看到一堆英文就吓到了,结果是道水题ORZ

Accepted 4414 0MS 232K 1726 B C++ free斩

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std; const int maxn = 60;
char map[maxn][maxn];
int n; bool check(int x, int y)
{
int lenUp = 0;
//up
for(int j = y-1; j >= 0; j--) //向上走确定十字架的形状
{
if(map[x][j] != '#') break;
else if(map[x-1][j] == '#' || map[x+1][j] == '#') return false;
else lenUp++;
}
if(lenUp == 0) return false; //down
int lenDown = 0;
for(int j = y+1; j < n; j++)
{
if(map[x][j] != '#') break;
else if(map[x-1][j] == '#' || map[x+1][j] == '#') return false;
else lenDown++;
}
if(lenDown != lenUp) return false; int lenLeft = 0;
for(int i = x-1; i >= 0; i--)
{
if(map[i][y] != '#') break;
else if(map[i][y-1] == '#' || map[i][y+1] == '#') return false;
else lenLeft++;
}
if(lenLeft != lenUp) return false; int lenRight = 0;
for(int i = x+1; i < n; i++)
{
if(map[i][y] != '#') break;
else if(map[i][y-1] == '#' || map[i][y+1] == '#') return false;
else lenRight++;
}
if(lenRight != lenUp) return false; return true;
}
int main()
{
while(scanf("%d", &n) != EOF)
{
if(n == 0) break;
memset(map,'o',sizeof(map)); for(int i = 0; i < n; i++)
{
scanf("%s", map[i]);
} int ans = 0;
for(int i = 1; i < n-1; i++)
{
for(int j = 1; j < n-1; j++)
{
if(map[i][j] == '#' && check(i,j))
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}

hdu 4414 Finding crosses【简单模拟】的更多相关文章

  1. hdu 4414 Finding crosses

    题目链接:hdu 4414 其实是一道简单的字符型水题,不涉及任何算法,可比赛时却没能做出来,这几天的状态都差到家了... 题目大意是求有多少个满足条件的十字架,十字架的边不能有分叉路口,所以枚举每个 ...

  2. HDU 4414 Finding crosses(dfs)

    Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...

  3. HDU 4414 Finding crosses (DFS + BFS)

    题意:在N*N的图中,找出孤立存在的十字架的个数.十字架要求为正十字,孤立表示组成十字架的‘#的周围的一格再无’#‘. dfs找出在中心的‘#’(周围四格也为‘#'),则缩小了搜索范围,再bfs找出是 ...

  4. HDOJ 4414 Finding crosses 暴力!

    Finding crosses Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  5. hdu 4858 容器的简单模拟

    我用临接表模拟容器超时 #include<stdio.h> #include<string.h> #include<vector> using namespace ...

  6. HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...

  7. 【HDU 4452 Running Rabbits】简单模拟

    两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时).初始方向dir(E.N.W.S)和左转周期turn(小时/次). 各自每小时往 ...

  8. (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&lt;=3,输出剩下的人 )

    题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  9. HDU 4509 湫湫系列故事——减肥记II (简单模拟)

    题意:一天一共有1440分钟,主人公每天有n件事要做,给出这n件事开始跟结束的时间,然后让你求出,空闲的时间的总分钟数是多少. 解题报告:简单模拟,只要开个一维数组标记那个每个分钟是否是有事的就可以了 ...

随机推荐

  1. Python-爬虫-针对有frame框架的页面

    有的页面会使用frame 框架,使用Selenium + PhantomJS 后并不会加载iframe 框架中的网页内容.iframe 框架相当于在页面中又加载了一个页面,需要使用Selenium 的 ...

  2. Linux增加挂载盘

    命令:fdisk /dev/sdb, m 命令:m,n,e,1,p,w 命令:mkfs -t ext4 /dev/sdb,y 挂载命令:mount -t ext4 /dev/sdb /data 获取U ...

  3. wp8手机浏览器项目

    项目需求如下: 1.页面布局 最上方为搜索/网址框 中间为网页显示区,默认主页为百度搜索 最下方为功能栏,分别有后退,前进,窗口和更多功能 在更多功能中有 分享给好友 发送网址到桌面 查看历史记录等 ...

  4. EffectiveJava(4)通过私有构造器强化不可实例化的能力

    通过私有构造器强化不可实例化的能力 原理:只有当类不包含显式的构造器时,编译器才会生成缺省的构造器,因此只要让这个类包含私有构造器,他就不能被实例化 这种方式下,子类没有可访问的超类构造器可调用 // ...

  5. Node.js 网页瘸腿爬虫初体验

    延续上一篇,想把自己博客的文档标题利用Node.js的request全提取出来,于是有了下面的初哥爬虫,水平有限,这只爬虫目前还有点瘸腿,请看官你指正了. // 内置http模块,提供了http服务器 ...

  6. mongodb在Windows安装配置及遇到的问题、java连接测试

    一.安装 1.访问mongodb的官网http://www.mongodb.org/downloads下载64bit的包,我下载的是mongodb-win32-x86_64-2008plus-ssl- ...

  7. sql server内置函数

    MSDN标准文档:https://msdn.microsoft.com/zh-cn/library/ff848784(v=sql.120).aspx 配置函数 select @@servername ...

  8. Application provided invalid, non monotonically increasing dts to muxer in stream

    很多同学在使用Ffmpeg过程中都遇到Application provided invalid, non monotonically increasing dts to muxer in stream ...

  9. 安装java运行环境

    1.查看java安装版本 执行命令java -version查看已安装java运行环境信息. 2.下载JDK 到sun官网下载需要的jdk版本,地址为:http://www.oracle.com/te ...

  10. web service json 数组解析

     boolean workexpMark = true;     // 美发师工作经历json数组解析     org.json.JSONObject jsonObject = new org.j ...