zoukankan      html  css  js  c++  java
  • Zoj3944

    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 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
    

    Author: Lu, Yi
    Source: The 13th Zhejiang Provincial Collegiate Programming Contest

    统计小人个数;  泪流满面!!

    #include <cstdio>
    #include <cstring>
    #define N 110
    char G[N][N]; int v[N][N];
    int n , m;
    using namespace std ;
    void check()
    {
            for(int i=0; i< n; i++)
                    for( int j=0; j<m; j++)
                    {
                        printf("%c", G[i][j]);
                        if(j== m-1) printf("
    ");
                    }
    }
    bool judge(int a, int b)
    {
        if(a>= 0&& a< n && b>= 0 && b < m) 
            return true;
        else 
            return false;
    }
    int main()
    {
        int t; scanf("%d", &t);
        while(t--)
        {
            scanf("%d%d", &n, &m);    
            for(int i=0; i <n; i++)
            {
                scanf ("%s", G[i]);
            }
            int sum= 0;
            for(int i=0; i< n; i++)
                for(int j=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
    ", sum);
        }
        
        return 0;
    }
  • 相关阅读:
    C#中关于@的用法
    c++ 中__declspec 的用法
    #pragma详细解释(一)
    memmove 和 memcpy的区别
    【niubi-job——一个分布式的任务调度框架】----安装教程
    [异能程序员]第一章 酒后事发(第一更)
    博客园的最后一篇博文,还是要离开了(附带个人博客源码分享)
    五一假期——技术之路上的坎儿
    deerlet-redis-client添加集群支持,邀请各路大神和菜鸟加入。
    从日常开发说起,浅谈HTTP协议是做什么的。
  • 原文地址:https://www.cnblogs.com/soTired/p/5426728.html
Copyright © 2011-2022 走看看