hdu 4414 Finding crosses(模拟)

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int nMax = 55;
int N;
char map[nMax][nMax];
int ans;
//int vis[nMax][nMax];

int checklr(int x, int y)
{
    if(map[x][y] == '#' && map[x][y - 1] == 'o' && map[x][y + 1] == 'o')
    return 1;
    return 0;
}

int checkud(int x, int y)
{
    if(map[x][y] == '#' && map[x - 1][y] == 'o' && map[x + 1][y] == 'o')
    return 1;
    return 0;
}

int dfs(int x, int y)
{
    int k;
    for(k = 1;x - k >= 0 && x + k <= N + 1 && y - k >= 0 && y + k <= N + 1; ++ k)
    {
        if(checklr(x + k, y) && checklr(x - k, y) && checkud(x, y + k) && checkud(x, y - k))
        continue;
        else if(map[x + k][y] != '#' && map[x - k][y] != '#' && map[x][y + k] != '#' && map[x][y - k] != '#')
        break;
        else return 0;
    }
    return k > 1;
}

int main()
{
    //cout << "Hello world!" << endl;
    //freopen("e://data.in", "r", stdin);
    while(scanf("%d", &N) != EOF)
    {
        if(!N) break;
        int i, j;
        for(i = 1; i <= N; ++ i)
        {
            scanf("%s", map[i] + 1);
        }
        for(i = 0; i <= N + 1; ++ i)
        map[0][i] = map[N + 1][i] = 'o';
        for(i = 0; i <= N + 1; ++ i)
        map[i][0] = map[i][N + 1] = 'o';
        ans = 0;
        //memset(vis, 0, sizeof(vis));
        for(i = 1; i <= N; ++ i)
        {
            for(j = 1; j <= N; ++ j)
            {
                if(map[i][j] == '#')
                {
                    //int
                    ans += dfs(i, j);
                    //int l = 0;
                    //while(l <= k) vis[i - l][j] = vis[i + l][j] = vis[i][j - l] = vis[i][j + l] = 1;
                }

            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

你可能感兴趣的:(include)