HDU 5319 Painter

来源:互联网 发布:医疗人工智能 杭州 编辑:程序博客网 时间:2024/06/04 19:35

HDU-5319

题意:画家每次只会画\ 或 /,并且用 R 画\ 用B 画/。如果一个点被BR都涂过,就会变成G。给出一张被画完的图,求它被画了几下。
解题思路:遇到B或G时判断它右上角是不是B或者G,如果都不是就代表要从这个点开始画一笔。R或G时判断左上角。

/*************************************************************************    > File Name: 0722e.cpp    > Author: Narsh    >     > Created Time: 2016年07月22日 星期五 19时52分37秒 ************************************************************************/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int n,t,tot,m;string s[300];int main() {    scanf("%d\n",&t);    s[0]="                                            ";    while (t--) {        scanf("%d\n",&n);        for (int i = 1; i <= n; i++)            cin>>s[i];        m=s[1].length();        for (int i = 1; i <= n; i++) {            s[i]=" "+s[i];        //  cout<<s[i]<<endl;        }        tot=0;        for (int i = 1; i <= n; i++)            for (int j = 1; j <= m; j++)                if (s[i][j] == 'G' || s[i][j]=='R')                     if (!(s[i-1][j-1] == 'R' || s[i-1][j-1] == 'G')) tot++;        for (int i = 1; i <= n; i++)            for (int j = 1; j <= m; j++)                if (s[i][j] == 'G' || s[i][j] == 'B')                    if (!(s[i-1][j+1] == 'B' || s[i-1][j+1] == 'G')) tot++;        printf("%d\n",tot);    }}
0 0
原创粉丝点击