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

2 篇文章 0 订阅

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

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

题意:就是数人数(人的一部分也算),就从头开始一部分一部分往下搜,很简单模拟就过。
.O.
/|\
(.)

#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
char s[150][150];
int n,m; 
int check(int ii,int jj)
{
    if(ii>=1 && ii<=n && jj>=1 && jj<=m)
    return 1;
    return 0;
}

void fun(int x,int y)
{
    s[x][y]='.';
    if(check(x+1,y-1)&&s[x+1][y-1]=='/')
        s[x+1][y-1]='.';
    if(check(x+1,y+1)&&s[x+1][y+1]=='\\')
        s[x+1][y+1]='.';
    if(check(x+1,y)&&s[x+1][y]=='|')
        s[x+1][y]='.';
    if(check(x+2,y-1)&&s[x+2][y-1]=='(')
        s[x+2][y-1]='.';
    if(check(x+2,y+1)&&s[x+2][y+1]==')')
        s[x+2][y+1]='.';
}
void fun2(int x,int y)
{

    s[x][y]='.';
    if(check(x,y+1)&&s[x][y+1]=='|')
        s[x][y+1]='.';
    if(check(x,y+2)&&s[x][y+2]=='\\')
        s[x][y+2]='.';
    if(check(x+1,y)&&s[x+1][y]=='(')
        s[x+1][y]='.';
    if(check(x+1,y+2)&&s[x+1][y+2]==')')
        s[x+1][y+2]='.';
}

void fun3(int x,int y)
{
    s[x][y]='.';
    if(check(x,y+1)&&s[x][y+1]=='\\')
        s[x][y+1]='.';
    if(check(x+1,y-1)&&s[x+1][y-1]=='(')
        s[x+1][y-1]='.';
    if(check(x+1,y+1)&&s[x+1][y+1]==')')
        s[x+1][y+1]='.';
} 
void fun4(int x,int y){
    s[x][y]='.';
    if(check(x+1,y-2)&&s[x+1][y-2]=='(')
        s[x+1][y-2]='.';
    if(check(x+1,y)&&s[x+1][y]==')')
        s[x+1][y]='.';
}
void fun5(int x,int y)
{
    s[x][y]='.';
    if(check(x,y+2)&&s[x][y+2]==')')
        s[x][y+2]='.';
}

int main()
{
    int sum;
    int i,j,t;
    cin>>t; 
    while(t--)
    {
        sum=0;
        cin>>n>>m;
        for(i=1; i<=n; i++)
            for(j=1; j<=m; j++)
                cin>>s[i][j];


        for(i=1; i<=n; i++)
        {
            for(j=1; j<=m; j++)
            {
                if(s[i][j]=='O')
                {
                    sum++;
                    fun(i,j);
                }
            }
        }

        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(s[i][j]=='/')
                {
                   fun2(i,j);
                   sum++;
                }

            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(s[i][j]=='|')
                {
                    fun3(i,j);
                    sum++;
                }
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(s[i][j]=='\\'){
                    fun4(i,j);
                    sum++;                  
                }
            }
        }

        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(s[i][j]=='(')
                {
                    fun5(i,j);
                    sum++;
                }
            }
        }

        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)
                if(s[i][j]==')')
                        sum++;
        cout<<sum<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值