hdu 4414 Finding crosses
题目链接:hdu 4414
其实是一道简单的字符型水题,不涉及任何算法,可比赛时却没能做出来,这几天的状态都差到家了。。。
题目大意是求有多少个满足条件的十字架,十字架的边不能有分叉路口,所以枚举每个点看是否满足条件就行,只是编码量的问题而已(感觉自己的码力不断下降了,我也不知道该怎么办好。。)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; char s[][];
int n; int check(int x, int y) {
if(s[x][y] != '#') return ;
int up = , down = , left = , right = ;
for(int i = x - ; i >= ; --i) {
if(s[i][y] == '#') ++up;
else break;
if(s[i][y - ] == '#' || s[i][y + ] == '#') return ;
}
if(up == ) return ; for(int i = x + ; i <= n - ; ++i) {
if(s[i][y] == '#') ++down;
else break;
if(s[i][y - ] == '#' || s[i][y + ] == '#') return ;
}
if(down == ) return ; if(up != down) return ; for(int j = y - ; j >= ; --j) {
if(s[x][j] == '#') ++left;
else break;
if(s[x - ][j] == '#' || s[x + ][j] == '#') return ;
}
if(left == ) return ; for(int j = y + ; j <= n - ; ++j) {
if(s[x][j] == '#') ++right;
else break;
if(s[x - ][j] == '#' || s[x + ][j] == '#') return ;
}
if(right == ) return ; if(left != right) return ; if(up != left) return ; return ;
} int main() {
while(~scanf("%d",&n),n) {
for(int i = ; i < n; ++i)
scanf("%s",s[i]);
int cnt = ;
for(int i = ; i < n - ; ++i)
for(int j = ; j < n - ; ++j)
if(check(i,j) == ) ++cnt;
printf("%d\n",cnt);
}
return ;
}
学到了这种调试方法,每一步的 return 值都不同,这样子调试程序时就能很清楚问题是出在哪儿,在哪儿的运行和自己想的不一样。原本我把 check 函数定义为 bool 返回类型,每个不合法的都返回 0,最后那个 return 才返回 1,这样子原则上可以,但一旦出错却不知错在哪一步,所以以后记得在编码上需灵活一些,别再纠结于那些所谓的节省内存等问题了!!!
hdu 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(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找出是 ...
- HDOJ 4414 Finding crosses 暴力!
Finding crosses Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU-4414 Finding crosses 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4414 直接暴力判断即可. //STATUS:C++_AC_15MS_232KB #include &l ...
- HDU 4668 Finding string (解析字符串 + KMP)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出一个压缩后的串,以及一个模式串,问模式串 ...
- hdu 4414 暴力枚举
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- HDU 5992 Finding Hotels(KD树)题解
题意:n家旅店,每个旅店都有坐标x,y,每晚价钱z,m个客人,坐标x,y,钱c,问你每个客人最近且能住进去(非花最少钱)的旅店,一样近的选排名靠前的. 思路:KD树模板题 代码: #include&l ...
- hdu 1937 Finding Seats
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
随机推荐
- [ios][opengles]GLKit如何搭一个app的框架
一个外文对GLKit的讲解: Beginning OpenGL ES 2.0 with GLKit Part 1 英文原文链接:http://www.raywenderlich.com/5223 ...
- python爬虫之Scrapy 使用代理配置
转载自:http://www.python_tab.com/html/2014/pythonweb_0326/724.html 在爬取网站内容的时候,最常遇到的问题是:网站对IP有限制,会有防抓取功能 ...
- libevent安装及使用
一.安装libevent 官网:http://libevent.org/ 选择最新版本下载,我选择的是libevent-2.0.22-stable.tar.gz,然后安装README文件中描述的方法编 ...
- 数据库 使用DML语句更改数据
使用DML语句更改数据 添加新数据: 插入单行语句: Insert into 表名(列名)values(‘值’); 插入多行:insert into 表名(列名,…..) Values(‘值’,’值’ ...
- Android权限安全(2)给基本组件自定义权限(以activity为例)
给基本组件自定义权限(以activity为例) 1.有访问权限的activity的定义端 1.1定义权限 <permission android:name="com.example.f ...
- Linux的启动过程
Linux的启动过程,也就是Linux的引导流程,这部分主要是理论知识. Linux的开机启动过程 1.1第一步--加载BIOS 当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的 ...
- 【leetcode❤python】101. Symmetric Tree
#-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):# def __init_ ...
- CodeForces 219C Color Stripe
Color Stripe Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- Quartz:ERROR threw an unhandled Exception
详细的错误信息如下: -- ::] ERROR org.quartz.core.JobRunShell: - Job group1.job1 threw an unhandled Exception: ...
- form 表单
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...