HDU 5319
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的更多相关文章
- hdu 5319 Painter(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5319 Painter(枚举)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- HDU 5319 Painter (模拟)
题意: 一个画家画出一张,有3种颜色的笔,R.G.B.R看成'\',B看成'/',G看成这两种的重叠(即叉形).给的是一个矩阵,矩阵中只有4种符号,除了3种颜色还有'.',代表没有涂色.问最小耗费多少 ...
- HDU 5319 Painter
题意:红色从左上向右下涂,蓝色从右上向左下涂,既涂红色又涂蓝色就变成绿色,问最少涂几下能变成给的图. 解法:模拟一下就好了,注意细节. 代码: #include<stdio.h> #inc ...
- 多校赛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 ...
- hdoj 5319 Painter(模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 思路分析:假设颜色R表示为1,颜色B表示为2,颜色G表示为3,因为数据量较小,采用暴力解法即可, ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- 页面关闭或刷新时触发javascript的事件
当页面在关闭或刷新时提示 window.onbeforeunload(function(){ //判断是关闭还是刷新 1.满足关闭,否则是刷新 if(event.clientX>document ...
- 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling
P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...
- 洛谷 P3133 [USACO16JAN]无线电联系Radio Contact
P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the ...
- IntelliJ IDEA could not autowire no beans of 'Decoder'
IntelliJ IDEA could not autowire no beans of 'Decoder' 学习了:http://blog.csdn.net/u012453843/article/ ...
- start_kernel——boot_cpu_init及PER_CPU
init/main.c /* * Activate the first processor. */ static void __init boot_cpu_init(void) { int cpu = ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com
错误如题. 原因:web.xml中的servlet映射<url-pattern> 配置错误 改动正确就可以. 我直接删除了,bug就攻克了. 另一个问题是 xxx.jar fail to ...
- C++_关于const 的全面总结
C++中的constkeyword的使用方法很灵活.而使用const将大大改善程序的健壮性.本人依据各方面查到的资料进行总结例如以下,期望对朋友们有所帮助. Const 是C++中经常使用的类型修饰符 ...
- CF 447B(DZY Loves Strings-贪心)
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- HDU 5296 Annoying problem dfs序 lca set
Annoying problem Problem Description Coco has a tree, whose nodes are conveniently labeled by 1,2,…, ...
- 用自定义的函数将gps转换为高德坐标
<?php echo<<<_END <!doctype html> <html> <head> <meta charset=" ...