HDU 5319 Painter(暴力)

Painter

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2463    Accepted Submission(s): 964


 

Problem Description

Mr. Hdu is an painter, as we all know, painters need ideas to innovate , one day, he got stuck in rut and the ideas dry up, he took out a drawing board and began to draw casually. Imagine the board is a rectangle, consists of several square grids. He drew diagonally, so there are two kinds of draws, one is like ‘\’ , the other is like ‘/’. In each draw he choose arbitrary number of grids to draw. He always drew the first kind in red color, and drew the other kind in blue color, when a grid is drew by both red and blue, it becomes green. A grid will never be drew by the same color more than one time. Now give you the ultimate state of the board, can you calculate the minimum time of draws to reach this state.

 

Input

The first line is an integer T describe the number of test cases.
Each test case begins with an integer number n describe the number of rows of the drawing board.
Then n lines of string consist of ‘R’ ‘B’ ‘G’ and ‘.’ of the same length. ‘.’ means the grid has not been drawn.
1<=n<=50
The number of column of the rectangle is also less than 50.
Output
Output an integer as described in the problem description.

 

Output

Output an integer as described in the problem description.

 

Sample Input

 

2 4 RR.B .RG. .BRR B..R 4 RRBB RGGB BGGR BBRR

 

Sample Output

 

3 6

题意:给你一个n行未知列(每一行字母数相同)的字符串矩阵,其中包含R,B,G。R只能从左上画到右下(反之也行),B只能从右上画到左下(反之也行),G表示这个格子同时被R和B画了。问最少画几次可以画出题目中给你的图案。

思路:感觉这道题就是完全考读题啊!!!读懂题意就是暴力了!!!

可以想到,如果一个格子为R或G,而它的右下方的格子不为R也不为G,则这里一定需要画一笔。B和G也一样。

因此只需要找必须停顿的点,累加笔画数就行了。(也可以找必须开始的点,原理一样)

注意:

1、字符串初始化为'.',否则会影响判断

2、不一定是n行n列!!!坑了我一发WA!!!

代码:

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 210
#define inf 1e9+7
using namespace std;
int n,m,k,p,ans,sum;
int a[maxn],b[maxn];
char s[maxn][maxn];
int main()
{
    int T,cas=1,x,y,c;
    while(scanf("%d",&T)!=EOF){
    while(T--){
     scanf("%d",&n);
     for(int i=0;i<maxn;i++)
     for(int j=0;j<maxn;j++)s[i][j]='.';
     for(int i=0;i<n;i++)scanf("%s",s[i]);
     ans=0;
     m=strlen(s[0]);
     for(int i=0;i<n;i++)
     for(int j=0;j<m;j++)
     if(s[i][j]!='.'){
         if((s[i][j]=='R'||s[i][j]=='G')&&(s[i+1][j+1]!='R'&&s[i+1][j+1]!='G'))ans++;
         if((s[i][j]=='B'||s[i][j]=='G')&&(s[i+1][j-1]!='B'&&s[i+1][j-1]!='G'))ans++;
     }
     printf("%d\n",ans);
    }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lsd20164388/article/details/81141589