People counting Time limit: 2 Seconds Memory Limit: 65536 KB
In a BG (dinner gathering) for Zju ICPC team, the coaches wanted to count the number of people present at the BG. They did, and the waitress take a photo for them. Everyone is in the photo and no one were completely blocked. Each person in the photo has the same posture. After some preprocessing, the photo is converted into a H×W character matrix with the background represented by ".". T Hus a person in this photo are 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 are partly blocked in the photo, only part of the above diagram would be presented in the character mat Rix.
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:
The first contains and integers H , W (1≤ H , W ≤100)-as described above, followed by H lines, Showi ng The matrix representation of the photo.
Output
For each test case, there should is a single line, containing an integer indicating the number of people from the photo.
Sample Input
3.o./| (.) 3 4OOO (/|\ ()))
Sample Output
14
Author: Lu, Yi
Source: The 13th Zhejiang Provincial Collegiate Programming Contest
Statistics of the number of villains; Tears!!
#include <cstdio>#include<cstring>#defineN 110CharG[n][n];intV[n][n];intN, M;using namespacestd;voidCheck () { for(intI=0; i< N; i++) for(intj=0; j<m; J + +) {printf ("%c", G[i][j]); if(j== m1) printf ("\ n"); }}BOOLJudgeintAintb) { if(a>=0&& a< N && b>=0&& B <m)return true; Else return false;}intMain () {intT scanf"%d", &t); while(t--) {scanf ("%d%d", &n, &m); for(intI=0; I <n; i++) {scanf ("%s", G[i]); } intsum=0; for(intI=0; i< N; i++) for(intj=0; j< m; J + +) { if(g[i][j]=='.')Continue; if(g[i][j]=='O') {sum+=1; G[I][J]='.'; if(Judge (i+1, j) && g[i+1][j]=='|') g[i+1][j]='.'; if(Judge (i+1, J-1) &&g[i+1][j-1]=='/') g[i+1][j-1]='.'; if(Judge (i+1, j+1) &&g[i+1][j+1]=='\\') g[i+1][j+1]='.'; if(Judge (i+2, J-1) &&g[i+2][j-1]=='(') g[i+2][j-1]='.'; if(Judge (i+2, j+1) &&g[i+2][j+1]==')') g[i+2][j+1]='.'; } if(g[i][j]=='/') {sum+=1; G[I][J]='.'; if(Judge (I, j+1) &&g[i][j+1]=='|') g[i][j+1]='.'; if(Judge (I, j+2) &&g[i][j+2]=='\\') g[i][j+2]='.'; if(Judge (i+1, j) &&g[i+1][j]=='(') g[i+1][j]='.'; if(Judge (i+1, j+2) &&g[i+1][j+2]==')') g[i+1][j+2]='.'; } if(g[i][j]=='|') {sum+=1; G[I][J]='.'; if(Judge (I, j+1) &&g[i][j+1]=='\\') g[i][j+1] ='.'; if(Judge (i+1, J-1) &&g[i+1][j-1]=='(') g[i+1][j-1]='.'; if(Judge (i+1, j+1) &&g[i+1][j+1]==')') g[i+1][j+1]='.'; } if(g[i][j]=='\\') {sum+=1; G[I][J]='.'; if(Judge (i+1, j) &&g[i+1][j]==')') g[i+1][j]='.'; if(Judge (i+1, J-2) &&g[i+1][j-2]=='(') g[i+1][j-2]='.'; } if(g[i][j]=='(') {sum+=1; G[I][J]='.'; if(Judge (i,j+2) &&g[i][j+2]==')') g[i][j+2]='.'; } if(g[i][j]==')') {sum+=1; G[I][J]='.'; }} printf ("%d\n", sum); } return 0;}
Zoj3944-people counting