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. Notice: Undefined offset 的解决方法

    Notice: Undefined offset: 1 in D:\wwwroot\wr\askseo\404.php on line 5 Notice: Undefined offset: 2 in ...

  2. poj 1475 || zoj 249 Pushing Boxes

    http://poj.org/problem?id=1475 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=249 Pushin ...

  3. 科学计算器的Java实现

    简易的科学计算器的实现 ---Java版 import javax.swing.*;//新的窗口组件包 import java.awt.*; import java.awt.event.*; publ ...

  4. Python和Ruby开发中源文件中文注释乱码的解决方法(Eclipse和Aptana Studio3均适用)

    Eclipse的设置(Aptana Studio3与Eclipse基本完全相同,此处略) window->preferences->general->editors->text ...

  5. C++之路进阶——bzoj3524(Couriers)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser  gryz2016 Logout 捐赠本站 Notice:由于本OJ ...

  6. MYSQL数据库自动本地/异地双备份/MYSQL增量备份

    构建高安全电子商务网站之(网站文件及数据库自动本地/异地双备份)架构图 继续介绍Linux服务器文件备份,数据库备份,数据安全存储相关的电子商务系统架构.针对安全性有多种多样的解决方案,其中数据备份是 ...

  7. so baby come on~~

    http://www.cnblogs.com/mfryf/archive/2013/05/17/3083895.html

  8. 全国各地电信DNS服务器地址

    全国各地电信DNS服务器地址 北京DNS地址:202.96.199.133 202.96.0.133 202.106.0.20 202.106.148.1 202.97.16.195 上海DNS地址: ...

  9. java dom4j写入XML

    引用的两个jar包 dom4j-1.6.1.jar jaxen.jar //=========================代码 import java.io.FileWriter;import j ...

  10. sql 中各种锁随记

    一. 为什么要引入锁    多个用户同时对数据库的并发操作时会带来以下数据不一致的问题:    丢失更新  A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系 ...