第十三届浙江省大学生程序设计竞赛 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. Dreamweaver 扩展开发:文档路径等信息的处理

    //browseFile(fieldToStoreURL){ //getFullPath(filePathURL){ //getSimpleFileName() { //fixUpPath(docUR ...

  2. Android Studio vs. Eclipse ADT Comparison

    Android Studio 是一个新的基于 IntelliJ IDEA Android 的安卓开发环境,它对 Eclipse ADT 进行了改进并新增了功能. Feature Android Stu ...

  3. WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展

    一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要是对文本 ...

  4. golang-web框架revel一个表单提交的总结

    这里要介绍好是revel框架的表单post提交的列子,主要是用于入门学习,和一些知识点的讲解: 首先: 来了解一个问题那就是重复提交表单,做过form表单提交的同学都知道,如果表单提交后不做处理,那么 ...

  5. HTML光标样式

    HTML光标样式 把你的光标放到相应文字上鼠标显示效果   cursor:auto;   自动  cursor:zoom-in;   放大镜  cursor:zoom-out;   缩小镜  curs ...

  6. Netty简介

    Netty简介 Netty是由JBOSS提供的一个Java开源框架.Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高可靠性的网络服务器和客户端程序.和传统BIO不同,NI ...

  7. 关系数据库SQL之可编程性触发器

    前言 前面关系数据库SQL之可编程性函数(用户自定义函数)一文提到关系型数据库提供了可编程性的函数.存储过程.事务.触发器及游标,前文已介绍了函数.存储过程.事务,本文来介绍一下触发器的使用.(还是以 ...

  8. C# 系统托盘图标

    C# 系统托盘图标 WPF NotifyIcon 资料 网址: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon http://www. ...

  9. 如何实现一个php框架系列文章【6】mysql数据库

    实现一个mysql数据库封装需要考虑的问题 使用方便性 采用直接sql语句操作方式.只要会写sql语句,那么将没有其他学习成本. uctphp框架提供的dba辅助封装类,用会之后将爱不释手. 使用前需 ...

  10. activiti工作流的web流程设计器整合视频教程 SSM 和 独立部署

    本视频为activiti工作流的web流程设计器整合视频教程 整合Acitiviti在线流程设计器(Activiti-Modeler 5.21.0 官方流程设计器) 本视频共讲了两种整合方式 1. 流 ...