题目链接: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的更多相关文章

  1. hdu 4414 Finding crosses【简单模拟】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414 CSUST:点击打开链接 Finding crosses Time Limit: 2000/1000 ...

  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-4414 Finding crosses 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4414 直接暴力判断即可. //STATUS:C++_AC_15MS_232KB #include &l ...

  6. HDU 4668 Finding string (解析字符串 + KMP)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个压缩后的串,以及一个模式串,问模式串 ...

  7. hdu 4414 暴力枚举

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

  8. HDU 5992 Finding Hotels(KD树)题解

    题意:n家旅店,每个旅店都有坐标x,y,每晚价钱z,m个客人,坐标x,y,钱c,问你每个客人最近且能住进去(非花最少钱)的旅店,一样近的选排名靠前的. 思路:KD树模板题 代码: #include&l ...

  9. hdu 1937 Finding Seats

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. ajax 无刷新分页

    //ajax 无刷新分页1.前台要做的 滑动时 当前page+1,通过page ajax请求后台接口获取数据将数据进行拼装;2.后台要做的 做分页接口返回json数据前台判断触发请求条件: var p ...

  2. vs2013的asp.net 管理

    iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ASP.NETWebAdminFiles /vpath:/AS ...

  3. 关于plsql表如何创建自增长列

    1首先在sequence中创建新序列 在oracle中sequence就是所谓的序列号,每次取的时候它会自动增加,一般用在需要按序列号排序的地方. 这是语句创建 create sequence ide ...

  4. C#微信开发文档

    C#微信开发文档 开发前准备 微信公众平台链接: https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN 开发初期我们使用测 ...

  5. python 数据加密以及生成token和token验证

    代码如下: # -*- coding: utf-8 -*- from passlib.apps import custom_app_context as pwd_context import conf ...

  6. PowerShell处理RSS信息

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 环境:Windows Server 2012 EN(解决PowerShell控制台中文乱码问题:方 ...

  7. ssh 配置自动登录

    假定 机器A 连接至 机器B . 1. 在机器A上,生成RSA秘钥对 ssh-keygen -t rsa 期间passphrase不输入密码.默认生成文件至 ~/.ssh/ -rw------- we ...

  8. mysql 导入导出的几个常用参数

    导出命令: mysqldump -t --skip-extended-insert -utest -p testdb tableA > testdb_tableA.sql 参数说明: -t: 仅 ...

  9. java 7-nio异步I/O-将来式和回调式

    java7中三个异步通道 1.AsynchronousFileChannle:用于文件I/O 2.AsynchronousSockeChannle:用于套接字I/O,支持连接超时 3.Asynchro ...

  10. WDCP控制面板如何安装PDO_mysql组件

    http://osacar.iteye.com/blog/2098431 执行wget -c http://down.wdlinux.cn/in/pdo_mysql_ins.sh再执行chmod 75 ...