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( ...
随机推荐
- rtc关机闹钟6 AlarmManagerService研究
这个是 private void setLocked(int type, long when) { if (mNativeData != 0) { // The kernel n ...
- Android中的sharedUserId属性详解
在Android里面每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户可见,只对该应用程序自身可见,而我们可以使他们对其他的应用程序可见,这会使我们用到 ...
- noip2011提高组day1+day2解题报告
Day1 T1铺地毯https://www.luogu.org/problem/show?pid=1003 [题目分析] 全部读入以后从最后一个往前找,找到一个矩形的范围覆盖了这个点,那这个矩形就是最 ...
- [Codeforces626F] Group Projects (DP)
Group Projects Description There are n students in a class working on group projects. The students w ...
- JDBC连接属性
JDBC连接属性 hibernate.connection.driver_classs属性:设置连接数据库的驱动: hibernate.connection.url属性:设置所需连接数据库的URL: ...
- GMT时间转换
/// <summary> /// GMT时间转成本地时间 /// </summary> /// <param name="gmt">字符串形式 ...
- UVA 11795 七 Mega Man's Mission
七 Mega Man's Mission Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- 【转载】前端面试“http全过程”将所有HTTP相关知识抛出来了...
原文:前端面试“http全过程”将所有HTTP相关知识抛出来了... 来一篇串通,一个http全过程的问题,把所有HTTP相关知识点都带过一遍 http全过程 输入域名(url)-->DNS映射 ...
- 回归——线性回归,Logistic回归,范数,最大似然,梯度,最小二乘……
写在前面:在本篇博客中,旨在对线性回归从新的角度考虑,然后引入解决线性回归中会用到的最大似然近似(Maximum Likelihood Appropriation-MLA) 求解模型中的参数,以及梯度 ...
- js跨域及解决方案
本文出自:http://www.cnblogs.com/oneword/archive/2012/12/03/2799443.html 1.什么是跨域 我们经常会在页面上使用ajax请求访问其他服务器 ...