ZOJ3944 People Counting

ZOJ3939 The Lucky Week

1.PeopleConting

题意:照片上有很多个人,用矩阵里的字符表示。一个人如下:

.O.
/|\
(.)
占3*3格子,句号“.”为背景。没有两个人完全重合。有的人被挡住了一部分。问照片上有几个人。

题解:

先弄个常量把3*3人形存起来,然后6个部位依次找,比如现在找头,找到一个头,就把这个人删掉(找这个人的各个部位,如果在该部位位置的不是这个人的身体,就不删),删成句号,疯狂找就行了。

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 
 5 const int MAXN=111;
 6 const char man[3][3] = {    {'.','O','.'},
 7                             {'/','|','\\'},
 8                             {'(','.',')'}};
 9 const int X[6] = {0,1,1,1,2,2};
10 const int Y[6] = {1,0,1,2,0,2};
11 char a[MAXN][MAXN];
12 
13 int n,m;
14 
15 void delMan(int x,int y,int k){
16     int mx,my;
17     mx = x - X[k];
18     my = y - Y[k];
19     int i;
20     for(i=0; i<6; i++){
21         if(a[mx+X[i]][my+Y[i]]==man[X[i]][Y[i]]){
22             a[mx+X[i]][my+Y[i]] = '.';
23         }
24     }
25 }
26 
27 int farm(){
28     int i,j,k;
29     int sum=0;
30     for(k=0; k<6; k++){
31         char now = man[X[k]][Y[k]];
32         for(i=0; i<n; i++){
33             for(j=0; j<m; j++){
34                 if(a[i][j]==now){
35                     sum++;
36                     delMan(i,j,k);
37                 }
38             }
39         }
40     }
41     return sum;
42 }
43 
44 int main() {
45     int T,i,j;
46     scanf("%d",&T);
47     while(T--) {
48         scanf("%d%d",&n,&m);
49         for(i=0; i<n; i++)
50             for(j=0; j<m; j++) {
51                 scanf(" %c",&a[i][j]);
52             }
53         printf("%d\n",farm());
54     }
55 }
View Code

相关文章:

  • 2021-05-30
  • 2021-12-02
  • 2021-08-09
  • 2022-02-02
  • 2021-07-31
  • 2021-09-13
  • 2022-01-14
  • 2021-09-26
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2021-05-16
  • 2021-10-17
  • 2021-08-03
  • 2022-01-12
相关资源
相似解决方案