acm/icpc 浙江省赛 People Counting

水题,但是比赛的时候没写出来,思路是对的,但是竞赛的那种环境下,静不下下来,改了很多次都改不对,诶,心态还是太差,要努力的还有很多啊。

思路就是打一张相同大小的表,初始全部为0,当碰到头时,往下判断,如果是这个人身体的一部分,那就变为1,且cnt ++,一次判断,感觉题目好水啊,当时身边的队伍都挂了紫色气球,就我们队没有,好可惜。

#include<iostream>
#include<cstring>
using namespace std;
char s[105][105];
int  p[105][105];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int cnt=0;
        memset(s,0,sizeof(s));
        memset(p,0,sizeof(p));
        int a,b;
        cin>>a>>b;
        for(int i=0;i<a;i++)
            cin>>s[i];
        for(int i=0;i<a;i++)
            for(int j=0;j<b;j++)
            {
                if(s[i][j]=='O'&&!p[i][j])
                {
                    cnt++;
                    p[i][j]=1;
                    if(i+1<a&&s[i+1][j]=='|') p[i+1][j]=1;
                    if(i+1<a&&j-1>=0&&s[i+1][j-1]=='/') p[i+1][j-1]=1;
                    if(i+1<a&&j+1<b&&s[i+1][j+1]=='\\') p[i+1][j+1]=1;
                    if(i+2<a&&j-1>=0&&s[i+2][j-1]=='(') p[i+2][j-1]=1;
                    if(i+2<a&&j+1<b&&s[i+2][j+1]==')')  p[i+2][j+1]=1;
                }
                if(s[i][j]=='/'&&!p[i][j])
                {
                    cnt++;
                    p[i][j]=1;
                    if(j+1<b&&s[i][j+1]=='|') p[i][j+1]=1;
                    if(j+2<b&&s[i][j+2]=='\\') p[i][j+2]=1;
                    if(i+1<a&&s[i+1][j]=='(') p[i+1][j]=1;
                    if(i+1<a&&j+2<b&&s[i+1][j+2]==')') p[i+1][j+2]=1;
                }
                if(s[i][j]=='|'&&!p[i][j])
                {
                    cnt++;
                    p[i][j]=1;
                    if(j+1<b&&s[i][j+1]=='\\') p[i][j+1]=1;
                    if(i+1<a&&j-1>=0&&s[i+1][j-1]=='(') p[i+1][j-1]=1;
                    if(i+1<a&&j+1<b&&s[i+1][j+1]==')')  p[i+1][j+1]=1;
                }
                if(s[i][j]=='\\'&&!p[i][j])
                {
                    cnt++;
                    p[i][j]=1;
                    if(i+1<a&&j-2>=0&&s[i+1][j-2]=='(') p[i+1][j-2]=1;
                    if(i+1<a&&s[i+1][j]==')') p[i+1][j]=1;
                }
                if(s[i][j]=='('&&!p[i][j])
                {
                    cnt++;
                    p[i][j]=1;
                    if(j+2<b&&s[i][j+2]==')') p[i][j+2]=1;
                }
                if(s[i][j]==')'&&!p[i][j])
                {
                    cnt++;
                    p[i][j]=1;
                }
            }
        cout<<cnt<<endl;
    }
    return 0;
}


你可能感兴趣的:(acm/icpc 浙江省赛 People Counting)