多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- 欧拉通路-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 ...
- 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 ...
- 迷之节约 分类: sdutOJ 最小生成树 2015-06-24 19:10 10人阅读 评论(0) 收藏
迷之节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF超级有钱,最近又买了n个(1 <= n <= 300)小岛,为 ...
- 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 ...
- 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏
#include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bo ...
- short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- 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 ...
- 菊花加载第三方--MBprogressHUD 分类: ios技术 2015-02-05 19:21 120人阅读 评论(0) 收藏
上次说到了网络请求AFN,那么我们在网络请求的时候,等待期间,为了让用户不认为是卡死或程序出错,一般都会放一个菊花加载,系统有一个菊花加载类叫UIProgressHUD.但是我今天要说的是一个替代它的 ...
随机推荐
- Mybatis-Plugin插件学习使用方法
以下教程仅供学习使用,针对于IntelliJ Idea 15中的Mybatis Plugin插件. 作者博客中的教程:http://myoss.github.io/2016/MyBatis-Plugi ...
- devexpress13学习系列(四)PDFViewer(4)
PdfViewer的属性: CurrentPageNumber:显示当前页的页码. DocumentFilePath:当前文件. DocumentProperties:文件属性. PageCount: ...
- Fedora20 MATE Destop 环境下安装Sougoupinyin输入法+皮肤
卸载ibus # yum erase ibus* 选择性安装 fcitx # yum install fcitx fcitx-configtool $ ls -a $ vi .bashrc .bas ...
- linux [Fedora] 下的 "飞秋/飞鸽传书"
官方网址: http://www.msec.it/blog/?page_id=11 http://software.opensuse.org/download.html?project=home:co ...
- codevs 1506 传话
http://codevs.cn/problem/1506/ 1506 传话 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 题目描述 D ...
- ligerui+json_001_实现表格(grid)的后台数据显示、分页
代码下载地址: http://download.csdn.net/detail/poiuy1991719/8556841 效果: 需要导入的包: 01:编写界面:index.jsp <%@ pa ...
- IIS7.5解决应用程序池回收假死问题
使用windows server 2008 r2解决回收假死的问题. 具体做法是: 打开应用程序池 -> 高级设置 ->在“禁止重叠回收”里选择“true”,这样就有效避免了应用程序池回收 ...
- paper 58 :机器视觉学习笔记(1)——OpenCV配置
开始学习opencv! 1.什么是OpenCV OpenCV的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可 ...
- 夺命雷公狗—angularjs—10—angularjs里面的内置函数
我们没学一门语言或者框架,几乎里面都有各自的语法和内置函数,当然,强悍的angularjs也不例外,他的方法其实常用的没多少,因为很多都可以用源生jis几乎都能完成一大部分.. <!doctyp ...
- 关于更改MYECLIPSE JS 代码背景颜色
白色的背景,看花了眼,你想改一下编辑器的背景颜色,移步这里就可以了. 这时你高兴的打开编辑器,发现颜色确实变了,但是当你打开有JS的JSP时,你碉堡了,发现JS的背景颜色还是默认的, 看着让人纠结,好 ...