HDU-1045 Fire Net
2013-04-11 08:55
267 查看
#include<stdio.h> #include<string.h> char a[6][6]; int v[6][6],hash[6][6];//V标记是否已经放过,hash标记是否此位置是否进入过队列 int n,sum,max; struct N { int x,y; }; int judge(int x,int y) { int i,j; for(i = x+1; i <= n; i++) if(v[i][y]) return 0; else if(a[i][y] == 'X') break; for(i = x-1; i >= 1; i--) if(v[i][y]) return 0; else if(a[i][y] == 'X') break; for(i = y+1; i <= n; i++) if(v[x][i]) return 0; else if(a[y][i] == 'X') break; for(i = y-1; i >= n; i--) if(v[x][i]) return 0; else if(a[x][i] == 'X') break; return 1; } void bfs(int x,int y) { int i,j; sum = 0; struct N q[5000],t1,t; q[0].x = x; q[0].y = y; int s = 0,e = 1; int fx[] = {-1,-1, 1, 1}; int fy[] = { 1,-1,-1, 1}; while(s != e) { t.x = q[s].x; t.y = q[s].y; s++; if(a[t.x][t.y] == '.' && !v[t.x][t.y]) { if(judge(t.x,t.y)) { v[t.x][t.y] = 1; sum++; } } for(i = 0;i < 4; i++) { t1.x = t.x + fx[i]; t1.y = t.y + fy[i]; if(t1.x >= 1 && t1.x <= n && t1.y >= 1 && t1.y <= n && !hash[t1.x][t1.y]) { hash[t1.x][t1.y] = 1; q[e].x = t1.x; q[e].y = t1.y; e++; } } e %= 5000; s %= 5000; } if(max < sum) { max = sum; } } int main() { int i,j; while(scanf("%d%*c",&n) != EOF && n) { max = 0; for(i = 1;i <= n; i++) scanf("%s",a[i]+1); for(i = 1;i <= n; i++) for(j = 1;j <= n; j++) { memset(v,0,sizeof(v)); memset(hash,0,sizeof(hash)); if(a[i][j] == '.') { bfs(i,j); } } printf("%d\n",max); } return 0; }
相关文章推荐
- HDU1045 Fire Net(深搜DFS)
- hdu 1045 Fire Net(dfs)
- hdu 1045 Fire Net (dfs)
- hdu-1045 Fire Net(DFS)
- 【DFS 回溯】HDU 1045 Fire Net
- HDU 1045 Fire Net 最大二分图匹配
- hdu 1045 && zoj 1002 Fire Net(DFS && 二分图匹配)
- HDU 1045(Fire Net)题解
- hdu 1045 Fire Net(dfs)
- HDU1045 - Fire Net (深搜)
- HDU - 1045 Fire Net (二分匹配)
- HDU - 1045 - Fire Net (DFS)
- hdu 1045 Fire Net(贪心)
- hdu 1045 Fire Net(二分匹配 or 暴搜)
- HDU-1045-Fire Net
- hdu 1045 Fire Net (DFS java)
- HDU 1045 Fire Net (DFS)
- HDU 1045 Fire Net(DFS)
- ZOJ 1002 FZU 1098 HDU 1045 Fire Net
- hdu 1045 Fire Net(搜索)