HDU 4414 Finding crosses 暴力枚举
来源:互联网 发布:复杂网络画图工具 编辑:程序博客网 时间:2024/05/17 22:43
题意:在#o组成的n*n(3<=n<=50)的图中找到等长十字架长度至少为3,并且周围一圈没有#的十字架的个数。
题解:枚举每一个#假设其为一个合法十字架的中心位置即可。
Sure原创,转载请注明出处。
#include <iostream>#include <cstdio>using namespace std;const int maxn = 52;const int move[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};char map[maxn][maxn];int n;void read(){ for(int i=0;i<n;i++) { scanf("%s",map[i]); } return;}bool judge(int x,int y){ if(x >= 0 && y >= 0 && x < n && y < n && map[x][y] == '#') { return true; } return false;}bool check(int x,int y){ int i = 1; for(;;i++) { bool flag = true; for(int j=0;j<4;j++) { int tx = x + i * move[j][0]; int ty = y + i * move[j][1]; if(judge(tx , ty) == false) { flag = false; } else { int pos = (j + 1) % 4; int xx = tx + move[pos][0]; int yy = ty + move[pos][1]; if(judge(xx,yy)) return false; pos = (j + 3) % 4; xx = tx + move[pos][0]; yy = ty + move[pos][1]; if(judge(xx,yy)) return false; } } if(flag == false) break; } if(i == 1) return false; for(int j=0;j<4;j++) { int tx = x + i * move[j][0]; int ty = y + i * move[j][1]; if(judge(tx , ty)) return false; } return true;}void solve(){ int cnt = 0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(map[i][j] == '#') { if(check(i,j)) cnt++; } } } printf("%d\n",cnt); return;}int main(){ while(~scanf("%d",&n) && n) { read(); solve(); } return 0;}
- HDU 4414 Finding crosses 暴力枚举
- HDU ACM 4414 Finding crosses 暴力枚举
- HDU 4414 Finding crosses(暴力判断)
- HDU 4414 Finding crosses (暴力模拟)
- hdu-4414-Finding crosses
- hdu 4414 Finding crosses
- hdu 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414: Finding crosses
- hdoj 4414 Finding crosses 【枚举】
- hdu 4414Finding crosses(模拟)
- Finding crosses hdu 4414 dfs
- hdu 4414 Finding crosses 简单搜索
- hdu 4414 Finding crosses【简单模拟】
- HDU 4414 Finding crosses (DFS + BFS)
- HDU 4414 Finding crosses(dfs)
- 用Java时写的第一个小小RPG游戏程序(第一版)
- c++中goto语句用法
- abstract class和interface总结
- 线程池的原理和连接池的原理
- poj 2299 求逆序数
- HDU 4414 Finding crosses 暴力枚举
- 开始明白
- JAVA线程池原理以及几种线程池类型介绍
- 快速排序&归并排序
- 关于fork函数的执行问题(源于腾讯校招笔试题目)
- Learning Python : 3. iterator 迭代器
- hdu 4410 Boomerang (2012杭州网络赛1001)
- java InputStream读取数据问题
- Keyboard.Tracer.1.94.SERiAL-RED