4166. A-The implementation problem
Time Limit: 1.0 Seconds
Memory Limit: 65536K
Total Runs: 140
Accepted Runs: 34
Xiao Ming is very interesting for dot matrix. Xiao Ming also like the char such as N, T, E, S.
The dot matrix of N, T, E, S as follow:
#...# ##### ##### ##### ##..# ..#.. #.... #.... #.#.# ..#.. ##### ##### #..## ..#.. #.... ....# #...# ..#.. ##### #####
Now, Xiao Ming give you big dot matrix, you need to find the N, T, E, S and calculate the number of them. We can allow them clockwise rotating
90∘,180∘,270∘
90∘,180∘,270∘.
Input
The input consists of multiple test cases. The first line contains an integer T
T, indicating the number of test cases.
Each case will give you two integer n,m
n,m, means the row of dot matrix and column of dot matrix. And next input the dot matrix.(1≤n≤500,1≤m≤500)
(1≤n≤500,1≤m≤500)
Output
The number of N, T, E, S. such as sample output.
Sample Input
1 5 9 #...##### #.....#.. #####.#.. #.....#.. #.....#..
Sample Output
N: 0 T: 2 E: 0 S: 0
【分析】
爆搜...大模拟,判断有多少个NTES,强行判断就行了....反正只要够仔细就可以AC....否则debug眼睛会瞎的...
【代码】
#include<cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn=110;
#define eps 1e-8
char ss[510][510];
struct points{
int h,s;
}mar[510][510];
int main()
{
int pp,n,m,cn,ct,ce,cs;
scanf("%d",&pp);
while (pp--)
{
scanf("%d%d",&n,&m);
cn=ct=ce=cs=0;
for (int i=0;i<n;i++) scanf("%s",ss[i]);
for (int i=0;i<=510;i++)
for (int j=0;j<=510;j++)
mar[i][j].s=mar[i][j].h=0;
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
{
if (j>=2 && j<m-2 && ss[i][j]=='#' && ss[i][j-1]=='#' && ss[i][j-2]=='#' && ss[i][j+1]=='#' && ss[i][j+2]=='#') { mar[i][j].h=1; /*printf("heng=%d %d\n",i,j); */} else mar[i][j].h=0;
if (i>=2 && i<n-2 && ss[i][j]=='#' && ss[i-1][j]=='#' && ss[i-2][j]=='#' && ss[i+1][j]=='#' && ss[i+2][j]=='#') { mar[i][j].s=1; /*printf("shu=%d %d\n",i,j); */}else mar[i][j].s=0;
}
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
{
if (mar[i][j+2].h && mar[i+2][j+2].s) ct++;
if (mar[i+2][j+2].h && mar[i+2][j+4].s) ct++;
if (mar[i+2][j+2].h && mar[i+2][j].s) ct++;
if (mar[i+4][j+2].h && mar[i+2][j+2].s) ct++;
if (mar[i+2][j].s && mar[i+2][j+4].s && ss[i+1][j+1]=='#' && ss[i+2][j+2]=='#' && ss[i+3][j+3]=='#' ) cn++;
if (mar[i][j+2].h && mar[i+4][j+2].h && ss[i+1][j+3]=='#' && ss[i+2][j+2]=='#' && ss[i+3][j+1]=='#' ) cn++;
if (mar[i][j+2].h && mar[i+2][j+2].h && mar[i+4][j+2].h)
{
if (mar[i+2][j].s) ce++;
if (mar[i+2][j+4].s) ce++;
if (ss[i+1][j]=='#' && ss[i+3][j+4]=='#') cs++;
}
if (mar[i+2][j].s && mar[i+2][j+2].s && mar[i+2][j+4].s)
{
if (mar[i][j+2].h) ce++;
if (mar[i+4][j+2].h) ce++;
if (ss[i+4][j+1]=='#' && ss[i][j+3]=='#') cs++;
}
}
printf("N: %d\n",cn);
printf("T: %d\n",ct);
printf("E: %d\n",ce);
printf("S: %d\n",cs);
}
return 0;
}