第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题。

ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3944

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 /////////////////////////////////////////////////////////////////////////
刚读完题的我是无比懵逼的。。。
冷静下来,发现有几点对解题还是有用的。
1 每个人都至少有一部分漏出来。
2 大家的站姿相同,也就是说,每个人躯体的各个部分的相对位置是确定的。如果你找到了一只手,那么在确定的地方可能会出现这个人的另一只手。。。 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <stdlib.h>
# define MAXN 110
typedef long long int LL;
using namespace std; char in[MAXN][MAXN];
int t, p, w;
int head[5][2] = {{1,-1}, {1,0}, {1,1}, {2,-1}, {2,1}};
char headwing[6] = {"/|\\()"};
int leftarm[5][2] = {{-1,1}, {0,1}, {0,2}, {1,0}, {1,2}};
char leftarmwing[6] = {"O|\\()"};
int mid[5][2] = {{-1,0}, {0,-1}, {0,1}, {1,-1}, {1,1}};
char midwing[6] = {"O/\\()"};
int rightarm[5][2] = {{-1,-1}, {0,-2}, {0,-1}, {1,-2}, {1,0}};
char rightarmwing[6] = {"O/|()"};
int leftleg[5][2] = {{-2,1}, {-1,0}, {-1,1}, {-1,2}, {0,2}};
char leftlegwing[6] = {"O/|\\)"};
int rightleg[5][2] = {{-2,-1}, {-1,-2}, {-1,-1}, {-1,0}, {0,-2}};
char rightlegwing[6] = {"O/|\\("}; void check(int i, int j){
    
     int k = 0, x, y;
     if(in[i][j] == 'O'){
         
         for(k=0; k<5; ++k){
                x = i + head[k][0];
            y = j + head[k][1];    
            
    
             if(x < 0 || x>=p || y<0 || y>=w){
                 continue;
            }else{
                if(in[x][y] == headwing[k]){
                    in[x][y] = '.';
                }
            }
        }
         
     }else if(in[i][j] == '/'){
         
         for(k=0; k<5; ++k){
                x = i + leftarm[k][0];
            y = j + leftarm[k][1];    
             if(x < 0 || x>=p || y<0 || y>=w){
                 continue;
            }else{
                if(in[x][y] == leftarmwing[k]){
                    in[x][y] = '.';
                }
            }
        }
         
     }else if(in[i][j] == '|'){
         
         
         for(k=0; k<5; ++k){
                x = i + mid[k][0];
            y = j + mid[k][1];    
             if(x < 0 || x>=p || y<0 || y>=w){
                 continue;
            }else{
                if(in[x][y] == midwing[k]){
                    in[x][y] = '.';
                }
            }
        }
         
     }else if(in[i][j] == '\\'){
         
         for(k=0; k<5; ++k){
                x = i + rightarm[k][0];
            y = j + rightarm[k][1];    
             if(x < 0 || x>=p || y<0 || y>=w){
                 continue;
            }else{
                if(in[x][y] == rightarmwing[k]){
                    in[x][y] = '.';
                }
            }
        }
         
         
     }else if(in[i][j] == '('){
         
         for(k=0; k<5; ++k){
                x = i + leftleg[k][0];
            y = j + leftleg[k][1];    
             if(x < 0 || x>=p || y<0 || y>=w){
                 continue;
            }else{
                if(in[x][y] == leftlegwing[k]){
                    in[x][y] = '.';
                }
            }
        }
         
     }else if(in[i][j] == ')'){
         
         for(k=0; k<5; ++k){
                x = i + rightleg[k][0];
            y = j + rightleg[k][1];    
             if(x < 0 || x>=p || y<0 || y>=w){
                 continue;
            }else{
                if(in[x][y] == rightlegwing[k]){
                    in[x][y] = '.';
                }
            }
        }
         
     }    
    
    
    return ;
}
int main(){
    
    //freopen("in.txt", "r", stdin);
    scanf("%d", &t);
    
    while( t-- ){
        scanf("%d%d", &p, &w);
        getchar();
        
        memset(in, 0, sizeof(in));    
        for(int i=0; i<p; ++i){
            for(int j=0; j<w; ++j){
                scanf("%c", &in[i][j]);
            }
            getchar();
        }
    
        
        int ans = 0;
        for(int i=0; i<p; ++i){
            for(int j=0; j<w; ++j){
                
                if(in[i][j] == '.'){
                    continue;
                }else{
                
                    ans ++;
                    check(i,j);
                    in[i][j] = '.';
                }
                
            }
        }
        
        cout << ans << endl;
    }     return 0;
} // 代码写的这么长,真的很抱歉 :(。

ZOJ People Counting的更多相关文章

  1. [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)

    Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...

  2. ZOJ 2392 The Counting Problem(模拟)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1368 题目大意:计算从S到T中所有的数,其中0,1,2,3,4,5, ...

  3. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...

  4. ZOJ 3080 ChiBi(spfa)

    ZOJ Problem Set - 3080 ChiBi Time Limit: 5 Seconds      Memory Limit: 32768 KB watashi's mm is so pr ...

  5. zoj 3286 Very Simple Counting---统计[1,N]相同因子个数

    Very Simple Counting Time Limit: 1 Second      Memory Limit: 32768 KB Let f(n) be the number of fact ...

  6. ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

  7. TOJ 1258 Very Simple Counting

    Description Let f(n) be the number of factors of integer n. Your task is to count the number of i(1 ...

  8. ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】

    Count the Colors Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  9. zoj 1610 Count the Colors 【区间覆盖 求染色段】

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

随机推荐

  1. SQL Server-数据类型(七)

    前言 前面几篇文章我们讲解了索引有关知识,这一节我们再继续我们下面内容讲解,简短的内容,深入的理解,Always to review the basics. 数据类型 SQL Server支持两种字符 ...

  2. Android开发之Activity的生命周期以及加载模式

    本篇博客就来好好的搞一下Activity的生命周期,如果搞过iOS的小伙伴的话,Activity的生命周期和iOS中ViewController的生命周期非常类似.生命周期,并不难理解.一个人的生命周 ...

  3. UWP开发之Mvvmlight实践五:SuspensionManager中断挂起以及复原处理

    最近比较忙有一段时间没有更新了,再接再厉继续分享. 案例下载:https://github.com/NewBLife/UWP/tree/master/SuspendSample 先我们看看App在生命 ...

  4. MySQL用户管理

    主要总结MySQL进行用户管理的基本实现,包含MySQL登录,添加用户,删除用户,为用户分配权限,移除某用户的权限,修改密码,查看权限等基本操作,所有命令均亲测实现.本博文是本人的劳动成果所得,在博客 ...

  5. ASP.NET Core 中文文档 第二章 指南(8) 使用 dotnet watch 开发 ASP.NET Core 应用程序

    原文:Developing ASP.NET Core applications using dotnet watch 作者:Victor Hurdugaci 翻译:谢炀(Kiler) 校对:刘怡(Al ...

  6. ASP.NET Core 中文文档 第四章 MVC(2.1)模型绑定

    原文:Model Binding 作者:Rachel Appel 翻译:娄宇(Lyrics) 校对:许登洋(Seay).何镇汐 模型绑定介绍 ASP.NET Core MVC 中的模型绑定从 HTTP ...

  7. scikit-learn一般实例之六:构建评估器之前进行缺失值填充

    本例将会展示对确实值进行填充能比简单的对样例中缺失值进行简单的丢弃能获得更好的结果.填充不一定能提升预测精度,所以请通过交叉验证进行检验.有时删除有缺失值的记录或使用标记符号会更有效. 缺失值可以被替 ...

  8. 用JWT来保护我们的ASP.NET Core Web API

    在上一篇博客中,自己动手写了一个Middleware来处理API的授权验证,现在就采用另外一种方式来处理这个授权验证的问题,毕竟现在也 有不少开源的东西可以用,今天用的是JWT. 什么是JWT呢?JW ...

  9. [Asp.net 5] ApplicationBuilder详解

    ApplicationBuilder(IApplicationBuilder接口),是OWIN的基础,而且里面都是代理.代理的代理,各种lambda表达式,估计要看这部分代码,很多人得头昏脑涨.今天就 ...

  10. Debian8安装Vim8

    1 安装vim需要的库 apt-get build-dep vim-gtk apt-get install libncurses5-dev mercurial   2 下载Vim8 apt-get i ...