HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3

来源:互联网 发布:知乎三国和战国 编辑:程序博客网 时间:2024/05/21 21:02

传送门

Painter

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


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 个字符串,这 n 个字符串的长度都是一样的,这就相当于是一个 nm

的矩阵(m 是字符串的长度),然后开始都是初始状态,然后题目给你一个最终状态,

只能用”\”和”/”两种方式涂,让你求从初始状态到达最终状态最少需要几步。其

中”\”这个方向的是涂红色。”/”这个方向的是涂蓝色。

解题思路:

就是暴力来找,假如说我们用 “\” 的方式来涂色,我们需要找到那个开头,也就是假

a[i][j] 这个状态的左上面没有红色和绿色就算是开头了, ans++,同理当用 “/”

这个方式来涂色也是一样的道理。

My Code

/**2016 - 08 - 24 下午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e2+5;const int MOD = 1e9+7;const double eps = 1e-7;const double PI = acos(-1);using namespace std;LL Scan_LL()///输入外挂{    LL res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}int Scan_Int()///输入外挂{    int res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}void Out(LL a)///输出外挂{    if(a>9)        Out(a/10);    putchar(a%10+'0');}int a[MAXN][MAXN];char str[MAXN][MAXN];int main(){    int T;    T = Scan_Int();    while(T--)    {        int m;        m = Scan_Int();        for(int i=0; i<m; i++)            scanf("%s",str[i]);        int n = strlen(str[0]);        memset(a, 0, sizeof(a));        for(int i=0; i<m; i++)        {            for(int j=0; j<n; j++)            {                if(str[i][j] == 'R')                    a[i+1][j+1] = 1;                else if(str[i][j] == 'B')                    a[i+1][j+1] = 2;                else if(str[i][j] == 'G')                    a[i+1][j+1] = 3;                else                    a[i+1][j+1] = 0;            }        }        int sum = 0;        for(int i=1; i<=m; i++)        {            for(int j=1; j<=n; j++)            {                if(a[i][j]==3 || a[i][j]==1)                {                    if(!(a[i-1][j-1]==3 || a[i-1][j-1]==1))                        sum++;                }            }        }        for(int i=1; i<=m; i++)        {            for(int j=1; j<=n; j++)            {                if(a[i][j]==3 || a[i][j]==2)                {                    if(!(a[i-1][j+1]==3 || a[i-1][j+1]==2))                        sum++;                }            }        }        printf("%d\n",sum);    }    return 0;}
0 0