HDOJ 4414 Finding crosses 暴力!
Finding crosses
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1631    Accepted Submission(s): 868
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:
- It's made up of a horizontal segment of length M and a vertical segment of length M.
 - The horizontal segment and the vertical segment overlap at their centers.
 - A cross must not have any adjacent '#'.
 - 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
代码
const int maxn=55;
char map[maxn][maxn];
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int n;
bool ok(int x,int y){
	return x>=0&&x<n&&y>=0&&y<n;
}
bool check(int x,int y){
	int cnt=0;
	for(int i=1;i<=25;i++){
		int tmpc=0;
		for(int j=0;j<4;j++){
			int xx=x+dx[j]*i,yy=y+dy[j]*i;
			if(ok(xx,yy) && map[xx][yy]=='#'){
				tmpc++;
				if(j%2==0){
					if(yy>0&&map[xx][yy-1]=='#' || yy<n-1&&map[xx][yy+1]=='#')return false;
					cnt++;
				}
				else {
					if(xx>0&&map[xx-1][yy]=='#' || xx<n-1&&map[xx+1][yy]=='#')return false;
					cnt++;
				}
			}
		}
		if(tmpc==0)break;
		if(tmpc!=4)return false;
	}
	if(cnt%2==0&&cnt>0)return true;
	else return false;
}
int main(){
	while(scanf("%d",&n)&&n){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)scanf(" %c",&map[i][j]);
		}
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(map[i][j]=='#' && check(i,j))ans++;
			}
		}
		printf("%d\n",ans);
	}
}												
											HDOJ 4414 Finding crosses 暴力!的更多相关文章
- hdu 4414 Finding crosses【简单模拟】
		
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414 CSUST:点击打开链接 Finding crosses Time Limit: 2000/1000 ...
 - hdu 4414 Finding crosses
		
题目链接:hdu 4414 其实是一道简单的字符型水题,不涉及任何算法,可比赛时却没能做出来,这几天的状态都差到家了... 题目大意是求有多少个满足条件的十字架,十字架的边不能有分叉路口,所以枚举每个 ...
 - HDU 4414 Finding crosses(dfs)
		
Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...
 - HDU 4414 Finding crosses (DFS + BFS)
		
题意:在N*N的图中,找出孤立存在的十字架的个数.十字架要求为正十字,孤立表示组成十字架的‘#的周围的一格再无’#‘. dfs找出在中心的‘#’(周围四格也为‘#'),则缩小了搜索范围,再bfs找出是 ...
 - HDU-4414 Finding crosses 水题
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4414 直接暴力判断即可. //STATUS:C++_AC_15MS_232KB #include &l ...
 - HDOJ 1334 Perfect Cubes(暴力)
		
Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for n > ...
 - [GodLove]Wine93 Tarining Round #7
		
比赛链接: http://vjudge.net/contest/view.action?cid=47643#overview 比赛来源: 2012 ACM/ICPC Asia Regional Han ...
 - 暴力/思维 HDOJ 5386 Cover
		
题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...
 - 状态压缩 + 暴力 HDOJ 4770 Lights Against Dudely
		
题目传送门 题意:有n*m的房间,'.'表示可以被点亮,'#'表示不能被点亮,每点亮一个房间会使旁边的房间也点亮,有意盏特别的灯可以选择周围不同方向的房间点亮.问最少需要多少灯使得所有房间点亮 分析: ...
 
随机推荐
- Oracle基础结构认知—初识oracle【转】
			
Oracle服务器(oracle server)由实例和数据库组成.其中,实例就是所谓的关系型数据库管理系统(Relational Database Management System,RDBMS), ...
 - MySQL 5.7.17 Group Relication(组复制)搭建手册【转】
			
本博文介绍了Group Replication的两种工作模式的架构.并详细介绍了Single-Master Mode的部署过程,以及如何切换到Multi-Master Mode.当然,文末给出了Gro ...
 - Python基础之多线程事件Event
			
import threading,time class Boss(threading.Thread): def run(self): print("BOSS:伙计们今晚上加班到22:00&q ...
 - ArcMap2SLD使用
			
1.首先打开ArcMap,加载一副mxd地图: 2.打开ArcGIS2SLD,如下图所示: 3.选择样式文件的保存形式,一副mxd地图可能有多个图层,选中In Separate Dateien/In ...
 - laravel 中provider的理解和使用
			
https://segmentfault.com/q/1010000004640866
 - 《Javascript启示录》要点汇总
			
前言:本文是阅读<Javascript启示录>后的一个读书笔记,对本书的要点进行了一个归纳,不是原创内容哦.要想详细了解相关内容,请阅读原书. 对象是由存储值的已命名属性组成的. Java ...
 - 本地为Windows,使用Xshell登录Linux云主机
			
以某东的云主机为实例 1. 下载并安装远程登录软件 下载Xshell软件 下载后双击xshell5_5.0.1332.exe进行安装 2. 安装完成,打开Xshell,并点击新建,根据要求输入相应参数 ...
 - 一个文件系统过滤驱动的demo
			
因为没写过FSD过滤驱动,所以拿来练练手,没有什么技术含量.参考自Win内核安全与驱动开发. 先梳理一下大概的流程,就是怎么去绑定设备栈.怎么去过滤各种请求的. 首先肯定是要绑定设备栈的,来看下怎么绑 ...
 - JavaScript中构造函数
			
构造函数:函数的另一种执行方法,执行后创建对象,并创建原型对象. 原型链:对象访问构造函数的指针. Function函数:函数对象. Object函数:所有创建对象的祖辈对象,也是由Function对 ...
 - Struts 2 - Hello World Example
			
As you learnt from the Struts 2 architecture, when you click on a hyperlink or submit an HTML form i ...