zoukankan      html  css  js  c++  java
  • hdu 5319 Painter(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319

    Painter

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


    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
     
    Source
     
     
    题目大意:给一个空的长方形,长方形中有很多的正方形方格,现在要给方格涂色,输出最少步数到达,题目输出中给出的最终状态。
    特别注意:1、""这个方向的是涂红色。"/"这个方向的是涂蓝色。
         2、习惯先涂红色,再涂蓝色。红色和蓝色加起来变成绿色。
         3、中间会出现断点的情况,如果出现"."那么就算两步。
     
    详见代码。(选择了一种最直白的方法,没有优化的代码~)
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 int Map[110][110];
     8 char ch[110];
     9 
    10 int main()
    11 {
    12     int t;
    13     scanf("%d",&t);
    14     while (t--)
    15     {
    16         int n,m;
    17         scanf("%d",&n);
    18         memset(Map,0,sizeof(Map));
    19         for (int i=0;i<n;i++)
    20         {
    21             scanf("%s",ch);
    22             m=strlen(ch);
    23             for (int j=0;j<m;j++)
    24             {
    25                 if (ch[j]=='.')
    26                     Map[i][j]=0;
    27                 else if (ch[j]=='R')
    28                     Map[i][j]=1;
    29                 else if (ch[j]=='B')
    30                     Map[i][j]=-1;
    31                 else
    32                     Map[i][j]=2;
    33             }
    34         }
    35         int sum=0;
    36         for (int i=0;i<n;i++)
    37         {
    38             for (int j=0;j<m;j++)
    39             {
    40                 int x=i+1,y=j+1;
    41                 if (Map[i][j]==1)
    42                 {
    43                     sum++;
    44                     while (x<n&&y<m&&Map[x][y]!=0&&Map[x][y]!=-1)
    45                     {
    46                         if(Map[x][y]==2)
    47                             Map[x][y]=-1;
    48                         else
    49                             Map[x][y]=0;
    50                         x++;
    51                         y++;
    52                     }
    53                 }
    54                 else if (Map[i][j]==-1)
    55                 {
    56                     sum++;
    57                     x=i+1,y=j-1;
    58                     while (x>=0&&x<n&&y>=0&&y<m&&Map[x][y]!=0&&Map[x][y]!=1)
    59                     {
    60                         if(Map[x][y]==2)
    61                             Map[x][y]=1;
    62                         else
    63                             Map[x][y]=0;
    64                         x++;
    65                         y--;
    66                     }
    67                 }
    68                 else if (Map[i][j]==2)
    69                 {
    70                     sum++;
    71                     sum++;
    72                     x=i+1,y=j-1;
    73                     while (x<n&&y<m&&Map[x][y]!=0&&Map[x][y]!=1)
    74                     {
    75                         if(Map[x][y]==2)
    76                             Map[x][y]=1;
    77                         else
    78                             Map[x][y]=0;
    79                         x++;
    80                         y--;
    81                     }
    82                     x=i+1,y=j+1;
    83                     while (x>=0&&x<n&&y>=0&&y<m&&Map[x][y]!=0&&Map[x][y]!=-1)
    84                     {
    85                         if(Map[x][y]==2)
    86                             Map[x][y]=-1;
    87                         else
    88                             Map[x][y]=0;
    89                         x++;
    90                         y++;
    91                     }
    92                 }
    93             }
    94         }
    95         printf ("%d
    ",sum);
    96     }
    97     return 0;
    98 }
     
  • 相关阅读:
    android 使用广播监听网络状态
    Android获取文件目录路径
    android实现布局重叠
    文件存储到getfilesdir和getcache中的解析问题,原来是权限问题
    CodeForces 1047C Enlarge GCD(数论)题解
    html 空白汉字占位符&#12288;
    js 将json字符串转换为json兑现
    为什么jQuery要返回jQuery.fn.init对象
    transform和transition
    自适应网页设计/响应式Web设计
  • 原文地址:https://www.cnblogs.com/qq-star/p/4688291.html
Copyright © 2011-2022 走看看