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;
}

最新文章

  1. wordpress目录文件结构说明
  2. Python学习之路--select解析
  3. 几种web数据渲染模板对比
  4. JavaScript Scoping and Hoisting
  5. Java for LeetCode 053 Maximum Subarray
  6. Git补丁
  7. 教-----------有时候就是那么纠结,教的时候不提问题,好像很懂,最后又来纠缠你!真是ctmb
  8. 原生 JavaScript 代码和Jquery实现对比
  9. 《C++游戏开发》笔记十四 平滑过渡的战争迷雾(二) 实现:真正的迷雾来了
  10. JuiceSSh破解分析
  11. POJ 1703 Find them, Catch them (数据结构-并查集)
  12. 一些CSS命名规则
  13. C#里CheckListBox的全选
  14. 基于ThreadPoolExecutor,自定义线程池简单实现
  15. UVA11846-Finding Seats Again(DFS)
  16. HDU 1716:排列2(全排列)
  17. Spring Websocket实现文本、图片、声音、文件下载及推送、接收及显示(集群模式)
  18. JERSEY中文翻译(第一章、Getting Started、1.1.7)
  19. python细节问题
  20. python的return

热门文章

  1. WEB开发兼容性---浏览器渲染模式—— document.compatMode
  2. Ruby print
  3. [ReactVR] Start a Virtual Reality Project Using the React VR CLI
  4. jsoup抓取网页+具体解说
  5. POJ-3264-Balanced Lineup-单点更新
  6. Unity3d修炼之路:用Mesh绘制一个Cube
  7. 游标和动态SQL
  8. python部分
  9. CoreData 从入门到精通(五)CoreData 和 TableView 结合
  10. m_Orchestrate learning system---一、amazeui如何使用