Multi-University Training Contest 3 — 1004题

来源:互联网 发布:办公室平台软件 编辑:程序博客网 时间:2024/05/21 05:56

Multi-University Training Contest 3  — 1004

Painter

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

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

24RR.B.RG..BRRB..R4RRBBRGGBBGGRBBRR

 

Sample Output

36

 

题目大意:在一个网格上画画

行数告诉了

但是列数不确定

可以用strlen来求

求测试数据中隐含的信息

本来是一个空白的网格

在上面作画

必须是斜着往上面撒颜料

只能是从左上方到右下

或者右上到坐下

一笔挥出不能间断

从左上到右下的笔画必须是红色的颜料

右上到坐下必须是蓝色颜料

两种颜色相互融合会变为绿色

现在已知最后这块网格的颜色分布


问最少需要画多少笔能达到现在的效果。 

算是一道模拟题吧,从两个不同的角度(左上到右下,右上到坐下)扫描,绿色可以当做红色也可以当做蓝色来判断,记下有多少条连续的颜色段,就是所要的结果。

 

 

#include<iostream>

#include<string.h>

using namespace std;

char map[52][52];

int main()

{

    int t, hangshu,lieshu;

    cin >> t;

    while (t--)

    {

        memset(map, 0, sizeof(map));

        cin >> hangshu;

        for (int i = 0; i < hangshu; i++)

            cin >> map[i];

        lieshu=strlen(map[0]);

        int s = 0;

        for (int i = 0,j=0; i < hangshu ; i++)

        {

            bool lianxu = false;

            for (int ii = i, jj = j; ii < hangshu&&jj < lieshu; ii++, jj++)

            {

                if (map[ii][jj] == 'R' || map[ii][jj] == 'G')

                {

                    if (lianxu == false)

                    {

                        lianxu = true;

                        s++;

                    }

                }

                else

                    lianxu = false;

            }

        }

        for (int i = 0, j = 1; j < lieshu; j++)

        {

            bool lianxu = false;

            for (int ii = i, jj = j; ii < hangshu&&jj < lieshu; ii++, jj++)

            {

                if (map[ii][jj] == 'R' || map[ii][jj] == 'G')

                {

                    if (lianxu == false)

                    {

                        lianxu = true;

                        s++;

                    }

                }

                else

                    lianxu = false;

            }

        }

        for (int i = 0, j = 0; j < lieshu; j++)

        {

            bool lianxu = false;

            for (int ii = i, jj = j; ii < hangshu&&jj >= 0; ii++, jj--)

            {

                if (map[ii][jj] == 'B' || map[ii][jj] == 'G')

                {

                    if (lianxu == false)

                    {

                        lianxu = true;

                        s++;

                    }

                }

                else

                    lianxu = false;

            }

        }

        for (int i = 1, j = lieshu-1; i < hangshu; i++)

        {

            bool lianxu = false;

            for (int ii = i, jj = j; ii < hangshu&&jj >= 0; ii++, jj--)

            {

                if (map[ii][jj] == 'B' || map[ii][jj] == 'G')

                {

                    if (lianxu == false)

                    {

                        lianxu = true;

                        s++;

                    }

                }

                else

                    lianxu = false;

            }

        }

        cout << s << endl;

    }

    return 0;

}

 

0 0
原创粉丝点击