D - Painter

Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u

Submit

Status

Practice

HDU 5319

Appoint description:

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

此题比较坑

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm> using namespace std; const int MAX = 110; char s[MAX][MAX]; int len,n; void DFS_R(int i,int j)
{
if(i<0||i>=n||j<0||j>=len)
return ;
if(s[i][j]!='G'&&s[i][j]!='.'&&s[i][j]!='B')
{
s[i][j]='.';
DFS_R(i+1,j+1);
DFS_R(i-1,j-1); }
else if(s[i][j]=='G')
{
s[i][j]='B';
DFS_R(i+1,j+1);
DFS_R(i-1,j-1);
}
}
void DFS_B(int i,int j)
{
if(i<0||i>=n||j<0||j>=len)
return ;
if(s[i][j]!='G'&&s[i][j]!='.'&&s[i][j]!='R')
{
s[i][j]='.';
DFS_B(i-1,j+1);
DFS_B(i+1,j-1); }
else if(s[i][j]=='G')
{
s[i][j]='R';
DFS_B(i-1,j+1);
DFS_B(i+1,j-1);
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
getchar();
for(int i=0; i<n; i++)
{
scanf("%s",s[i]); }
len=strlen(s[0]);
int sum=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<len; j++)
{
if(s[i][j]!='.')
{
if(s[i][j]=='B')
{
DFS_B(i,j);
sum++;
}
else if(s[i][j]=='R')
{
DFS_R(i,j);
sum++;
}
else
{
DFS_B(i,j);
DFS_R(i,j);
sum+=2;
}
}
}
}
printf("%d\n",sum);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏的更多相关文章

  1. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  2. 欧拉通路-Play on Words 分类: POJ 图论 2015-08-06 19:13 4人阅读 评论(0) 收藏

    Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10620 Accepted: 3602 Descri ...

  3. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

  4. 迷之节约 分类: sdutOJ 最小生成树 2015-06-24 19:10 10人阅读 评论(0) 收藏

    迷之节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF超级有钱,最近又买了n个(1 <= n <= 300)小岛,为 ...

  5. Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏

    #include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bo ...

  7. short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...

  8. Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏

    Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...

  9. 菊花加载第三方--MBprogressHUD 分类: ios技术 2015-02-05 19:21 120人阅读 评论(0) 收藏

    上次说到了网络请求AFN,那么我们在网络请求的时候,等待期间,为了让用户不认为是卡死或程序出错,一般都会放一个菊花加载,系统有一个菊花加载类叫UIProgressHUD.但是我今天要说的是一个替代它的 ...

随机推荐

  1. mysql 执行状态分析 show processlist

    SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...

  2. sublime text 快速补全

    sublime text 快速补全 关于补全,其实有很多,记录一些常用的在这里,忘记了可以查找 nav>ul>li    <nav>          <ul>  ...

  3. mesos资源动态分配测试

    测试集群配置 60CPU,320G RAM 测试内容:先运行一个需要60CPU的Application1,再运行一个需要50CPU的Application2. 结果分析 如果要等Application ...

  4. :nth-child()和:nth-of-type(n)区别

    ele:nth-child(n) 父元素下第n个元素且这个元素为ele ele:nth-of-type(n) 指父元素下第n个ele元素

  5. Script to set the Purchase Order Status to ‘OPEN’(将采购订单重新打开)

    Business Requirement: The finance user requests the IT team to change the PO status to OPEN as they ...

  6. LR Socket 测试demo

    建议像我这样最开始未接触过的,还是先从简单录制开始.录制完之后,分析测试脚本,再学习,再自己根据需要编写测试脚本. 第一:录制. A.    B. 选择需要录制的exe的目录 ,填写完后点击ok. C ...

  7. 【sublime】解决汉字输入的办法——InputHelper;在sublime中输入汉字==》InputHelper方法

    手工安装办法: cd ~/.config/sublime-text-2/Packages  #如果是sublime3就改一下 git clone https://github.com/xgenvn/I ...

  8. Native OR WebApp ?

    前两天刚好和一帮产品同学聊过,特指一个APP里面的各页面应该怎么做,大家的总结如下,原理一样,关键是了解Native和Web各自的优劣势:1. 偏交互的Native,偏浏览的Web:交互指复杂操作,输 ...

  9. 解决 “invalid resource directory name”, resource “crunch”

        try this: from the menu click Project->Clean... a popup window will appear. select the check ...

  10. IOS程序常用目录

    <Home>/AppName.app   应用程序本身包目录 <Home>/Documents/       应用程序的重要数据文件和用户数据文件等都放在这个目录, iTune ...