Painter



Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 816    Accepted Submission(s): 376





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.



 

Sample Input

2

4

RR.B

.RG.

.BRR

B..R

4

RRBB

RGGB

BGGR

BBRR

 





Sample Output

3

6

//遍历一遍地图 当碰到R的时候这一斜对角线都变为'.' 当碰到G的时候变为B

// 由于R和B 的方向不同 要推断两次  对角线有可能没有所有画完  一条对角线有可能画多次

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char s[60][60]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
gets(s[i]);
int ans=0;
int len=strlen(s[0]);
for(int i=0;i<n;i++)
{
for(int k=0;k<len;k++) //注意长度
{
int t=k;
if((s[i][k]=='R')||(s[i][k]=='G'))
{
ans++;
for(int j=i;j<n&&t<len;j++)
{ if(s[j][t]=='.'||s[j][t]=='B')
break;
if(s[j][t]=='G')
s[j][t]='B';
else if(s[j][t]=='R')
s[j][t]='.';
t++;
}
}
t=k;
if((s[i][k]=='B')||(s[i][k]=='G'))
{
ans++;
for(int j=i;j<n&&t>=0;j++)
{ if(s[j][t]=='.'||s[j][t]=='R')
break;
if(s[j][t]=='G')
s[j][t]='R';
else if(s[j][t]=='B')
s[j][t]='.';
t--;
}
}
} }
printf("%d\n",ans);
}
return 0;
}

HDU 5319的更多相关文章

  1. hdu 5319 Painter(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others)   ...

  2. HDU 5319 Painter(枚举)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  3. HDU 5319 Painter (模拟)

    题意: 一个画家画出一张,有3种颜色的笔,R.G.B.R看成'\',B看成'/',G看成这两种的重叠(即叉形).给的是一个矩阵,矩阵中只有4种符号,除了3种颜色还有'.',代表没有涂色.问最小耗费多少 ...

  4. HDU 5319 Painter

    题意:红色从左上向右下涂,蓝色从右上向左下涂,既涂红色又涂蓝色就变成绿色,问最少涂几下能变成给的图. 解法:模拟一下就好了,注意细节. 代码: #include<stdio.h> #inc ...

  5. 多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏

    D - Painter Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status P ...

  6. hdoj 5319 Painter(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 思路分析:假设颜色R表示为1,颜色B表示为2,颜色G表示为3,因为数据量较小,采用暴力解法即可, ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. MyEclipse 设置JSP,HTML的默认打开方式,避免出现打开后上面出现浏览器

    1. 2. 3. jsp的设置一样,这样myeclipse打开jsp就不会出现上面的浏览器了

  2. SpringBoot+Maven聚合多项目打包成jar

    已我最近自己在玩的一个DEMO为例 taosir为pom.xml,其他子项目均为其modules,且为jar项目 eureka为注册中心.workflow为提供者.entrance为调用方 entra ...

  3. ucore_lab0

    一直想好好学习一下操作系统课程,去一个Mooc网站上找了一门操作系统的课程.这便是里面的配套实验. 实验指导:点这里 lab0主要是准备相关的操作环境.课程推荐使用qemu作为硬件模拟器,推荐运行环境 ...

  4. [BZOJ1975]HH去散步 图论+矩阵

    ###[BZOJ1975]HH去散步 图论+矩阵 题目大意 要求出在一个m条边,n个点的图中,相邻两次走的边不能相同,求在t时间时从起点A走到终点B的路径方案总数.将答案mod45989 输入格式: ...

  5. $.ajax() 获取不到return 返回值

    /*常见错误示例 直接在 ajax 里面return 结果 */ function demo(){ $.ajax({ url : 'test.do', type : "post", ...

  6. 常用类属于哪些jar包

    1.@requestmapping注解,属于org.springframework.web.bind.annotation包下.org.springframework.web jar包. 2.@Res ...

  7. java string遇到的一个奇葩bug

    String abc = "1"; HashMap<String, String> hMap = new HashMap<String, String>() ...

  8. kqueue演示样例

    网络server通常都使用epoll进行异步IO处理,而开发人员通常使用mac,为了方便开发.我把自己的handy库移植到了mac平台上. 移植过程中,网上竟然没有搜到kqueue的使用样例.让我吃惊 ...

  9. lua简单类的实现

    原文地址:http://blog.csdn.net/qqmcy/article/details/37725177 类实现: MyClass = class("MyClass") - ...

  10. JDBC-连接数据库代码

    package com.zxc.connection; import java.sql.Connection; import java.sql.DriverManager; public class ...