zoj 3944

182人阅读 评论(0) 收藏 举报
分类:
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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 HW (1 ≤ HW ≤ 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

深搜思维,把一个器官周围的器官全部消去,类似于深搜的八连通问题,然而比赛时并没有联想到这一层

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char str[200][200];
void dfs1(int x, int y);
void dfs2(int x, int y);
void dfs3(int x, int y);
void dfs4(int x, int y);
void dfs5(int x, int y);
void dfs6(int x, int y);
int n, m;


int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(str,0,sizeof(str));
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            scanf(" %s",str[i]);
        }
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(str[i][j]=='O')
                {
                    cnt++;
                    dfs1(i,j);
                }
                else if(str[i][j]=='|')
                {
                    cnt++;
                    dfs2(i,j);
                }
                else if(str[i][j]=='/')
                {
                    cnt++;
                    dfs3(i,j);
                }
                else if(str[i][j]=='\\')
                {
                    cnt++;
                    dfs4(i,j);
                }
                else if(str[i][j]=='(')
                {
                    cnt++;
                    dfs5(i,j);
                }
                else if(str[i][j]==')')
                {
                    cnt++;
                    dfs6(i,j);
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


void dfs1(int x, int y)
{
    str[x][y]='.';
    if(x+1<n&&str[x+1][y]=='|')
    {
        str[x+1][y]='.';
    }
    if(x+1<n&&y-1>=0&&str[x+1][y-1]=='/')
    {
        str[x+1][y-1]='.';
    }
    if(x+1<n&&y+1<m&&str[x+1][y+1]=='\\')
    {
        str[x+1][y+1]='.';
    }
    if(x+2<n&&y-1>=0&&str[x+2][y-1]=='(')
    {
        str[x+2][y-1]='.';
    }
    if(x+2<n&&y+1<m&&str[x+2][y+1]==')')
    {
        str[x+2][y+1]='.';
    }
    return ;
}




void dfs2(int x, int y)
{
    str[x][y]='.';
    if(y+1<m&&str[x][y+1]=='\\')
    {
        str[x][y+1]='.';
    }
    if(x+1<n&&y-1>=0&&str[x+1][y-1]=='(')
    {
        str[x+1][y-1]='.';
    }
    if(x+1<n&&y+1<m&&str[x+1][y+1]==')')
    {
        str[x+1][y+1]='.';
    }
    return ;
}




void dfs3(int x, int y)
{
    str[x][y]='.';
    if(y+1<m&&str[x][y+1]=='|')
    {
        str[x][y+1]='.';
    }
    if(y+2<m&&str[x][y+2]=='\\')
    {
        str[x][y+2]='.';
    }
    if(x+1<n&&str[x+1][y]=='(')
    {
        str[x+1][y]='.';
    }
    if(x+1<n&&y+2<m&&str[x+1][y+2]==')')
    {
        str[x+1][y+2]='.';
    }
    return ;
}


void dfs4(int x, int y)
{
    str[x][y]='.';
    if(x+1<n&&y-2>=0&&str[x+1][y-2]=='(')
    {
        str[x+1][y-2]='.';
    }
    if(x+1<n&&str[x+1][y]==')')
    {
        str[x+1][y]='.';
    }
    return ;
}




void dfs5(int x, int y)
{
    str[x][y]='.';
    if(y+2<m&&str[x][y+2]==')')
    {
        str[x][y+2]='.';
    }
    return ;
}


void dfs6(int x, int y)
{
    str[x][y]='.';
    return ;
}

查看评论

zoj 3944 暴力 People Counting

题意:在一幅照片里统计人的数量; 思路:从上到下,从左到右, 只要不是点,它必定是人身体的一部分, 那么把它周边和该点属于同一个身体的位置变成点,暴力即可 题目链接: http:/...
  • wyt734933289
  • wyt734933289
  • 2016-04-23 21:45:13
  • 566

ZOJ 3944 People Counting(思维/技巧/模拟)

题目:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3944 代码: #include #include using na...
  • qq_32473657
  • qq_32473657
  • 2016-05-04 13:38:50
  • 352

ZOJ-3944 People Counting From 第13届浙江省赛

ZOJ-3944 People Counting Fr 第13届浙江省赛
  • no_alternantive
  • no_alternantive
  • 2016-04-24 09:21:57
  • 493

ZOJ 3944 People Counting

People Counting Time Limit: 2 Seconds      Memory Limit: 65536 KB In a BG (dinner gathering) f...
  • jtjy568805874
  • jtjy568805874
  • 2016-04-23 23:23:29
  • 519

bzoj 3944: Sum (杜教筛)

题目描述传送门题目大意: ans1=∑ni=1φ(i)ans1=\sum_{i=1}^n \varphi(i), ans2=∑ni=1μ(i)ans2=\sum_{i=1}^n \mu(i) n...
  • clover_hxy
  • clover_hxy
  • 2017-02-28 15:36:54
  • 251

HDU3944-DP?(帕斯卡公式+Lucas定理)

DP? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 128000/128000 K (Java/Others) Total S...
  • mowayao
  • mowayao
  • 2014-08-11 15:46:23
  • 764

[BZOJ3944]Sum(杜教筛)

题目描述传送门题解杜教筛裸题 我不会手写hash表… 讲解移步:http://blog.csdn.net/clove_unique/article/details/66991109代码#inclu...
  • Clove_unique
  • Clove_unique
  • 2017-03-28 10:22:03
  • 743

ZOJ解题报告ZOJ解题报告

  • 2010年08月02日 13:41
  • 282KB
  • 下载

zoj 3944 People Counting

In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people prese...
  • ACM__dongsheng
  • ACM__dongsheng
  • 2016-04-23 23:41:12
  • 580

BZOJ 3944 Sum 数论

题目大意:求∑ni=1φ(i)\sum_{i=1}^n\varphi(i)和∑ni=1μ(i)\sum_{i=1}^n\mu(i)。 n≤231−1n\leq2^{31}-1 令F(n)F(n)...
  • PoPoQQQ
  • PoPoQQQ
  • 2015-04-13 11:17:39
  • 3983
    文章
    个人资料
    持之以恒
    等级:
    访问量: 11万+
    积分: 7652
    排名: 3519
    最新评论