hdu 5319 Painter (此题纪念不仔细读题而逝去的WA)

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
   
   
   
   
2 4 RR.B .RG. .BRR B..R 4 RRBB RGGB BGGR BBRR
 

Sample Output
3
6

题意:给出一张行数为n的图(列数不定但每行长度相等),现在你有两把刷子,红刷子R只能按照斜率为-1 “\” 的方向刷,蓝刷子B只能按照斜率为1 "/" 的方向刷,红蓝刷子同时扫过的地方变为G,现在问你最少要多少次刷好整张图。

分析:对于每条斜边直接扫一遍红蓝刷子,数据小暴力过。

  • 一定注意是长方形而不是正方形
  • 一定注意红刷子只能 “\”刷,蓝刷子只能“/”刷


<span style="font-size:18px;">
//代码挫
#include<cstring>
#include<string>
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<vector>

using namespace std;

#define INF 0x3f3f3f3f

char g[55][55];

int dir[][5]={{1,1},{1,-1}};
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);

        for(int i=0;i<n;i++)
            scanf("%s",g[i]);

        int m=strlen(g[0]);

        int ans=0;
        for(int k=n-1;k>=0;k--)
        {
            int x=k;
            int y=0;
            int sum=0;
            while(x<n&&y<m)
            {
                if(g[x][y]=='R'||g[x][y]=='G') sum=1;
                else
                {
                    ans+=sum;
                    sum=0;
                }
                x+=dir[0][0];
                y+=dir[0][1];
            }

            ans+=sum;
        }

        for(int k=1;k<m;k++)
        {
            int y=k;
            int x=0;
            int sum=0;
            while(x<n&&y<m)
            {
                if(g[x][y]=='R'||g[x][y]=='G') sum=1;
                else
                {
                    ans+=sum;
                    sum=0;
                }
                x+=dir[0][0];
                y+=dir[0][1];
            }

            ans+=sum;
        }

        for(int k=0;k<m;k++)
        {
            int y=k;
            int x=0;
            int sum=0;
            while(x<n&&y>=0)
            {
                if(g[x][y]=='B'||g[x][y]=='G') sum=1;
                else
                {
                    ans+=sum;
                    sum=0;
                }
                x+=dir[1][0];
                y+=dir[1][1];
            }

            ans+=sum;
        }

        for(int k=1;k<n;k++)
        {
            int x=k;
            int y=m-1;
            int sum=0;
            while(x<n&&y>=0)
            {
                if(g[x][y]=='B'||g[x][y]=='G') sum=1;
                else
                {
                    ans+=sum;
                    sum=0;
                }
                x+=dir[1][0];
                y+=dir[1][1];
            }

            ans+=sum;
        }
        printf("%d\n",ans);
    }
    return 0;
}
 </span>



你可能感兴趣的:(hdu 5319 Painter (此题纪念不仔细读题而逝去的WA))