In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone was in the photo and no one was completely blocked. Each person in the photo has the same posture. After some preprocessing, the photo was converted into a H×W character matrix, with the background represented by ".". Thus a person in this photo is represented by the diagram in the following three lines:
.O. /|\ (.)
Given the character matrix, the coaches want you to count the number of people in the photo. Note that if someone is partly blocked in the photo, only part of the above diagram will be presented in the character matrix.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first contains two integers H, W (1 ≤ H, W ≤ 100) - as described above, followed by H lines, showing the matrix representation of the photo.
Output
For each test case, there should be a single line, containing an integer indicating the number of people from the photo.
Sample Input
2 3 3 .O. /|\ (.) 3 4 OOO( /|\\ ()))
Sample Output
1 4
和那道Defuse the Bomb一样 是The 13th Zhejiang Provincial Collegiate Programming Contest的题目。
这题当时理解错了题意,
OOO( /|\\ ()))中的右上角的那个 ( 我们以为是半个头。。
解题的思路是找到一个人后把此人其他部分删掉,只留一个,然后计数。
下面是ac代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
char a[200][200];
int main()
{
int zu,i,j,man,h,l;
scanf("%d",&zu);
while(zu--)
{
scanf("%d%d",&h,&l);
memset(a,0,sizeof(a));
for(i=1;i<=h;i++)
{
scanf("%s",a[i]+1);
}
man=0;
for(i=1;i<=h;i++)
{
for(j=1;j<=l;j++)
{
if(a[i][j]=='O')
{
if(a[i+1][j]=='|')
a[i+1][j]='.';
if(a[i+1][j-1]=='/')
a[i+1][j-1]='.';
if(a[i+1][j+1]==92)
a[i+1][j+1]='.';
if(a[i+2][j-1]=='(')
a[i+2][j-1]='.';
if(a[i+2][j+1]==')')
a[i+2][j+1]='.';
man++;
}
else if(a[i][j]==')')
{
if(a[i-2][j+1]=='O')
a[i-2][j+1]='.';
if(a[i-1][j]=='/')
a[i-1][j]='.';
if(a[i-1][j+1]=='|')
a[i-1][j+1]='.';
if(a[i-1][j+2]==92)
a[i-1][j+2]='.';
if(a[i][j-2]=='(')
a[i][j-2]='.';
man++;
}
else if(a[i][j]=='(')
{
if(a[i-2][j-1]=='O')
a[i-2][j-1]='.';
if(a[i-1][j]==92)
a[i-1][j]='.';
if(a[i-1][j-1]=='|')
a[i-1][j-1]='.';
if(a[i-1][j-2]=='/')
a[i-1][j-2]='.';
if(a[i][j+2]==')')
a[i][j+2]='.';
man++;
}
else if(a[i][j]=='|')
{
if(a[i+1][j-1]=='(')
a[i+1][j-1]='.';
if(a[i+1][j+1]==')')
a[i+1][j+1]='.';
if(a[i-1][j]=='O')
a[i-1][j]='.';
if(a[i][j-1]=='/')
a[i][j-1]='.';
if(a[i][j+1]==92)
a[i][j+1]='.';
man++;
}
else if(a[i][j]=='/')
{
if(a[i+1][j]=='(')
a[i+1][j]='.';
if(a[i+1][j+2]==')')
a[i+1][j+2]='.';
if(a[i][j+1]=='|')
a[i][j+1]='.';
if(a[i][j+2]==92)
a[i][j+2]='.';
if(a[i-1][j+1]=='O')
a[i-1][j+1]='.';
man++;
}
else if(a[i][j]==92)
{
if(a[i+1][j]==')')
a[i+1][j]='.';
if(a[i+1][j-2]=='(')
a[i+1][j-2]='.';
if(a[i-1][j-1]=='O')
a[i-1][j-1]='.';
if(a[i][j-1]=='|')
a[i][j-1]='.';
if(a[i][j-2]=='/')
a[i][j-2]='.';
man++;
}
}
}
printf("%d\n",man);
}
}