zoj 3944 暴力 People Counting

来源:互联网 发布:js 一切皆对象 编辑:程序博客网 时间:2024/05/20 04:14

题意:在一幅照片里统计人的数量;


思路:从上到下,从左到右, 只要不是点,它必定是人身体的一部分, 那么把它周边和该点属于同一个身体的位置变成点,暴力即可


题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3944


#include<set>#include<map>#include<queue>#include<vector>#include<cstdio>#include<climits>#include<iostream>#include<algorithm>using namespace std;int n, m, ans;char s[105][105];bool judge(int x, int y){    if(s[x][y] != '.') return true;    return false;}void change(int x, int y){    if(s[x][y] == 'O')    {        if(x+1 < m && y-1 >= 0 && s[x+1][y-1] == '/') s[x+1][y-1] = '.';        if(x+1 < m && s[x+1][y] == '|') s[x+1][y] = '.';        if(x+1 < m && y+1 < n && s[x+1][y+1] == '\\') s[x+1][y+1] = '.';        if(x+2 < m && y-1 >= 0 && s[x+2][y-1] == '(') s[x+2][y-1] = '.';        if(x+2 < m && y+1 < n && s[x+2][y+1] == ')') s[x+2][y+1] = '.';    }    else if(s[x][y] == '/')    {        if(y+1 < n && s[x][y+1] == '|') s[x][y+1] = '.';        if(y+2 < n && s[x][y+2] == '\\') s[x][y+2] = '.';        if(x+1 < m && s[x+1][y] == '(') s[x+1][y] = '.';        if(x+1 < m && y+2 < n && s[x+1][y+2] == ')') s[x+1][y+2] = '.';    }    else if(s[x][y] == '|')    {        if(y+1 < n && s[x][y+1] == '\\') s[x][y+1] = '.';        if(x+1 < m && y-1 >= 0 && s[x+1][y-1] == '(') s[x+1][y-1] = '.';        if(x+1 < m && y+1 < n && s[x+1][y+1] == ')') s[x+1][y+1] = '.';    }    else if(s[x][y] == '\\')    {        if(x+1 < m && y-2 >= 0 && s[x+1][y-2] == '(') s[x+1][y-2] = '.';        if(x+1 < m && s[x+1][y] == ')') s[x+1][y] = '.';    }    else if(s[x][y] == '(')    {        if(y+2 < n && s[x][y+2] == ')') s[x][y+2] = '.';    }    s[x][y] = '.';}int main(){    int t;    scanf("%d", &t);    while(t--)    {        ans = 0;        scanf("%d%d", &m, &n);        for(int i = 0; i < m; i++)            scanf("%s", s[i]);        for(int i = 0; i < m; i++)        {            for(int j = 0; j < n; j++)            {                if(judge(i, j)) ans++, change(i, j);            }        }        printf("%d\n", ans);    }    return 0;}


0 0
原创粉丝点击