题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319

Painter

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 826    Accepted Submission(s):
383

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.
 
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
 
Source
 
 
题目大意:给一个空的长方形,长方形中有很多的正方形方格,现在要给方格涂色,输出最少步数到达,题目输出中给出的最终状态。
特别注意:1、"\"这个方向的是涂红色。"/"这个方向的是涂蓝色。
     2、习惯先涂红色,再涂蓝色。红色和蓝色加起来变成绿色。
     3、中间会出现断点的情况,如果出现"."那么就算两步。
 
详见代码。(选择了一种最直白的方法,没有优化的代码~)
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int Map[][];
char ch[]; int main()
{
int t;
scanf("%d",&t);
while (t--)
{
int n,m;
scanf("%d",&n);
memset(Map,,sizeof(Map));
for (int i=;i<n;i++)
{
scanf("%s",ch);
m=strlen(ch);
for (int j=;j<m;j++)
{
if (ch[j]=='.')
Map[i][j]=;
else if (ch[j]=='R')
Map[i][j]=;
else if (ch[j]=='B')
Map[i][j]=-;
else
Map[i][j]=;
}
}
int sum=;
for (int i=;i<n;i++)
{
for (int j=;j<m;j++)
{
int x=i+,y=j+;
if (Map[i][j]==)
{
sum++;
while (x<n&&y<m&&Map[x][y]!=&&Map[x][y]!=-)
{
if(Map[x][y]==)
Map[x][y]=-;
else
Map[x][y]=;
x++;
y++;
}
}
else if (Map[i][j]==-)
{
sum++;
x=i+,y=j-;
while (x>=&&x<n&&y>=&&y<m&&Map[x][y]!=&&Map[x][y]!=)
{
if(Map[x][y]==)
Map[x][y]=;
else
Map[x][y]=;
x++;
y--;
}
}
else if (Map[i][j]==)
{
sum++;
sum++;
x=i+,y=j-;
while (x<n&&y<m&&Map[x][y]!=&&Map[x][y]!=)
{
if(Map[x][y]==)
Map[x][y]=;
else
Map[x][y]=;
x++;
y--;
}
x=i+,y=j+;
while (x>=&&x<n&&y>=&&y<m&&Map[x][y]!=&&Map[x][y]!=-)
{
if(Map[x][y]==)
Map[x][y]=-;
else
Map[x][y]=;
x++;
y++;
}
}
}
}
printf ("%d\n",sum);
}
return ;
}
 

hdu 5319 Painter(杭电多校赛第三场)的更多相关文章

  1. hdu 5326 Work(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. hdu 5373 The shortest problem(杭电多校赛第七场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 The shortest problem Time Limit: 3000/1500 MS (J ...

  3. hdu 5328 Problem Killer(杭电多校赛第四场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...

  4. HDU 5762 Teacher Bo (鸽笼原理) 2016杭电多校联合第三场

    题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<1 ...

  5. HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场

    题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过l ...

  6. HDU 5754 Life Winner Bo (各种博弈) 2016杭电多校联合第三场

    题目:传送门 题意:一个国际象棋棋盘,有四种棋子,从(n,m)走到(1,1),走到(1,1)的人赢,先手赢输出B,后手赢输出G,平局输出D. 题解:先把从(n,m)走到(1,1)看做是从(1,1)走到 ...

  7. HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题

    题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...

  8. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

  9. HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场

    题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...

随机推荐

  1. python编码iso-8859-9编码问题

    (2018-10-15) 路 2018骞�10鏈�16鏃�8:30鈥斺€�11:00锛屽湪鍏垽涓€搴叕寮€瀹$悊锛氬啀瀹$敵璇�.. (2018-10-15) 路 2018骞�10鏈�16鏃�8: ...

  2. 【前端学习笔记】call、apply、bind方法

    1.call()方法: // move函数实现移动平面图上一个点位置功能 var move = function(x,y){ this.x += x; this.y += y; } // 定一个点p ...

  3. java 常量 jvm在编译期能确定常量的 所以相等 但不能确定变量的范围 所以变量相加会产生新的

  4. LeetCode 671. Second Minimum Node In a Binary Tree

    Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...

  5. wp开发(三)--赚取收益篇

    App开发完毕了,是否有赚取收益的想法呢?下面很浅显地介绍两种常用赚取收益的方法. 一. 收费 在发布应用时,可以对应用进行定价,发布到商城之后,用户付费才可以下载,当然也可以提供试用版.收益状况可以 ...

  6. liunx 用户和用户组的命令

    查看用户列表     /etc/passwd  查看用户组列表 /etc/group 用户和用户组管理 groupadd groups 新增用户组 groupmod -n newgroupsr gro ...

  7. unity3D AR涂涂乐制作浅谈

    unity3D AR涂涂乐制作浅谈 AR为现在是虚拟现实较为火爆的一个技术,其中有个比较炫酷的就是AR涂涂乐的玩法,这个技术可以把扫描到的图片上的纹理 粘贴到模型上实现为模型上色的功能,但是我们需要怎 ...

  8. GDOI2015小Z的旅行路线

    GDOI2015小Z的旅行路线 题意: \(n\)个点的无根树,边上有权值. \(q\)个询问\(s\)和\(s\),问从\(s\)出发,找一条最长路(不经过重复点),保证路径上所有边边权不超过\(x ...

  9. NOIP2017结束了

    NOIP 2017 两天T1总分80 D1T3爆零 学军数据255 洛谷数据270 大概连1=都没有吧 没有预料到的结果 想了很久 最后只能选择接受 看完成绩单 高二爷们也许只剩下CYC LLQ ZS ...

  10. IT(然而其实是。。hdu5244?)

    Time Limit: 3000 ms Memory Limit: 256 MB Description IT = Inverse Transform 两个长度为 \(2^n\) 的序列 \(a,b\ ...