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\n",sum);
96     }
97     return 0;
98 }

 

 

转载于:https://www.cnblogs.com/qq-star/p/4688291.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值