HDU 5319 Painter (simulated brain problems)

Source: Internet
Author: User

Painter Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total Submission (s): 133 Accepted Submission (s):


Problem DescriptionMr. Hdu is an painter, as we all know, painters need ideas to innovate, one day, he got stuck in rut and the ideas Dr Y 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 is a kinds of draws, one is like ' \ ', and the other was 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 was drew by both Red and Blu E, it becomes green. A Grid would never is drew by the same color more than one time. Now give your The ultimate state of the board, can you calculate the minimum time of draws to reach this state. InputThe first line was an integer T describe the number of test cases.
Each test case begins with an integer number n describe the number of the 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.
 OutputOutput An integer as described in the problem description. Sample Input
24RR. B.rg. Brrb. R4rrbbrggbbggrbbrr
 Sample Output
36
 Sourcemulti-university Training Contest 3
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5319

The main idea: Brush the wall, can only press two oblique 45 degrees brush, one is red, one is blue, red meets blue to green, each lattice the same color only brush once, each brush must be a continuous paragraph, ask the answer target State at least a few times

Title analysis: Enumeration in two directions, \ This look like brush, if the current point is red or green and oblique before a point is not red and not green, it is necessary to brush once, the same way/so brush to judge, but why this is the smallest, because I only have to brush when the brush, so obviously this is the best

#include <cstdio> #include <cstring>char s[55][55];int main () {    int T;    scanf ("%d", &t);    while (t--)    {        int n;        scanf ("%d", &n);        for (int i = 1; I <= n; i++)            scanf ("%s", S[i] + 1);        int m = strlen (s[1] + 1);        int ans = 0;        for (int i = 1, i <= N; i++) for            (int j = 1; j <= M; j + +)                if (s[i][j] = = ' R ' | | s[i][j] = = ' G ')                    if (! ( S[i-1][j-1] = = ' R ' | | S[i-1][j-1] = = ' G '))                        ans + +;        for (int i = 1, i <= N; i++) for            (int j = 1; j <= M; j + +)                if (s[i][j] = = ' B ' | | s[i][j] = = ' G ')                    if (! ( S[i-1][j + 1] = = ' B ' | | S[i-1][j + 1] = = ' G '))                        ans + +;        printf ("%d\n", ans);}    }



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5319 Painter (simulated brain problems)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.