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 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- vue svg的使用
项目要求: 需要把websocket推送的数据进行展示.不停地刷掉旧的数据.但是需要根据数据坐标圈出来对应的车辆. 开始使用的是canvas进行画图,思路是使用absolute定位,for循环,在图片 ...
- 【转】C语言将字符串转换成对应的数字(十进制、十六进制)
转自:http://wawlian.iteye.com/blog/1315133 1.一个十进制数字的字符串表示转换成对应的整数.举例:将“1234”转换成整数1234 /*将字符串s转换成相应的整数 ...
- WEB开发兼容性---浏览器渲染模式—— document.compatMode
document.compatMode主要是用来判断浏览器采用何种方式渲染,它有两种可能的返回值:BackCompat和CSS1Compat,官方对其解释如下: BackCompat:标准兼容模式关闭 ...
- SpringBoot2.0中使用订阅redis的多个频道的消息
声明:参考文章:https://blog.csdn.net/myNameIssls/article/details/75471012?locationNum=2&fps=1 一·使用maven ...
- poi API大全
一. POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 二. HSSF概况 HSSF 是 ...
- 基于MySQL元数据的Hive的安装和简单測试
引言: Hive是一种强大的数据仓库查询语言,类似SQL,本文将介绍怎样搭建Hive的开发測试环境. 1. 什么是Hive? hive是基于Hadoop的一个数据仓库工具,能够将结构化的数据文件映射为 ...
- hdu1276(士兵队列训练问题) java集合水过
点击打开链接 有人说这题属于栈或者队列,个人认为说集合应该比較准确点. Problem Description 某部队进行新兵队列训练,将新兵从一開始按顺序依次编号.并排成一行横队,训练的规则例如以下 ...
- HTML5客户端数据存储机制Web Storage和Web SQL Database
引言 html5本地存储可以选择两种方式,一种是本地存储,一种是sqlite. 比如开发html5的购物车功能,就可以考虑选择其中之一,进行本地存储与操作. 又或者保存用户登录信息,可以使用local ...
- zzulioj--1609--求和(数学规律)
1609: 求和 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 209 Solved: 67 SubmitStatusWeb Board De ...
- Linux常用命令之rpm安装命令
转自:http://www.cnblogs.com/datasyman/p/6942557.html 在 Linux 操作系统下,几乎所有的软件均通过RPM 进行安装.卸载及管理等操作.RPM 的全称 ...