HDOJ - 4414 (Finding crosses)

/*
 PROG:   Finding crosses
 ID  :   
 LANG:   C++
 */
 //#pragma warnning (diaable : 4530)
 //#pragma warnning (disable : 4786)
 
 #include <set>
 #include <map>
 #include <list>
 #include <stack>
 #include <queue>
 #include <cmath>
 #include <string>
 #include <vector>
 #include <utility>
 #include <cmath>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <iostream>
 #include <fstream>
 #include <algorithm>
 
 using namespace std;
 
 #define DEBUG 0
 
 const int MAXN = 52;
 const int dx[] = {-1, 0, 1, 0};
 const int dy[] = {0, 1, 0, -1};
 
 int N;
 char graph[MAXN][MAXN];
 
 void readGraph() {
     for (int ix = 0; ix < N; ++ix)
         scanf("%s", graph[ix]);
 }
 
 bool isNotOkey(int x, int y) {
     return (x < 0 || y < 0 || x >= N || y >= N || graph[x][y] != '#');
 }
 
 int countGrids(int x, int y, int dir) {
     int ax, ay, ret = 0;
     
     while (!isNotOkey(x, y)) {
         ax = x + dx[(dir + 1) % 4];
         ay = y + dy[(dir + 1) % 4];
         if (!isNotOkey(ax, ay)) return 0;
 
         ax = x + dx[(dir + 3) % 4];
         ay = y + dy[(dir + 3) % 4];
         if (!isNotOkey(ax, ay)) return 0;
         
         ++ret, x += dx[dir], y += dy[dir];
     }// End of while
     return ret;
 }
 
 void Solve() {
     int cross = 0, grids[4] = {0};
     
     for (int ix = 0; ix < N; ++ix) {
         for (int jx = 0; jx < N; ++jx) {
             if (graph[ix][jx] == '#') {
                 memset(grids, 0, sizeof(grids));  // record the grids
                 for (int kx = 0; kx < 4; ++kx) {
                     int nx = ix + dx[kx];
                     int ny = jx + dy[kx];
                     grids[kx] = countGrids(nx, ny, kx);
                 }
                 if (grids[0] && grids[0] == grids[1]
                     && grids[0] == grids[2] && grids[0] == grids[3]) {
                     ++cross;
                 }
             }// End of if
         }
     }// End of for
     printf("%d\n", cross);
 }
 
 int main() {
 #if DEBUG
     freopen("E:\\hdoj_4414.in", "r", stdin);
     freopen("E:\\hdoj_4414.out", "w", stdout);
 #endif
 
     while (~scanf("%d", &N), N != 0) {
         readGraph();
         Solve();
     }// End of while
     return 0;
 }
 /*
 7
 ooo#ooo
 ooo#ooo
 o######
 ooo#ooo
 ooo#ooo
 ooo#ooo
 ooooooo
 0
 
 Run ID    Submit Time    Judge Status    Pro.ID    Exe.Time    Exe.Memory    Code Len.    Language    Author
 6847615    2012-10-01 15:29:57    Accepted    4414    0MS    232K    1833 B    C++    Maxwell
 */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值