题目链接: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. Java7 Fork-Join 框架:任务切分,并行处理

    概要 现代的计算机已经向多CPU方向发展,即使是普通的PC,甚至现在的智能手机.多核处理器已被广泛应用.在未来,处理器的核心数将会发展的越来越多.虽然硬件上的多核CPU已经十分成熟,但是很多应用程序并 ...

  2. hdu-题目:1058 Humble Numbes

    http://acm.hdu.edu.cn/showproblem.php?pid=1058 Problem Description A number whose only prime factors ...

  3. 【笔记】sublime 一些常用功能和快捷键

    Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑)Ctrl+G 跳转到相应的行Ctrl+J 合并行(已选择需要合并的多行时)Ctrl+L 选择整行(按住-继续选择下 ...

  4. php 单文件测试代码时必加入的代码

    有时候为了解决BUG,需要测试一些函数或代码最终实现的效果,来排除一些影响因素.这时候需要把代码单独拎出来,放在一个php单文件中来测试.在头部最好加上三句代码如下: <?php ini_set ...

  5. day 03 字符串 for 循环

    1.有变量量name = "aleX leNb" 完成如下操作: 1)移除 name 变量量对应的值两边的空格,并输出处理理结果 name = "aleX leNb&qu ...

  6. 【刷题】BZOJ 5293 [Bjoi2018]求和

    Description master 对树上的求和非常感兴趣.他生成了一棵有根树,并且希望多次询问这棵树上一段路径上所有节点深度的k 次方和,而且每次的k 可能是不同的.此处节点深度的定义是这个节点到 ...

  7. 【BZOJ1491】【NOI2007】社交网络(最短路,动态规划)

    [BZOJ1491][NOI2007]社交网络(最短路,动态规划) 题面 BZOJ 洛谷 图片是假的,只能到OJ上看 Description 在社交网络(socialnetwork)的研究中,我们常常 ...

  8. HDU.1846 Brave Game (博弈论 巴什博弈)

    HDU.1846 Brave Game (博弈论 巴什博弈) 题意分析 巴什博奕裸题 博弈论快速入门 代码总览 include <bits/stdc++.h> using namespac ...

  9. 开放接口/RESTful/Api服务的设计和安全方案

    总体思路 这个涉及到两个方面问题:一个是接口访问认证问题,主要解决谁可以使用接口(用户登录验证.来路验证)一个是数据数据传输安全,主要解决接口数据被监听(HTTPS安全传输.敏感内容加密.数字签名) ...

  10. Linux基础-----------nginx安装和nginx web、nginx反向代理、nfs 服务

    作业一:nginx服务1)二进制安装nginx包 yum install epel-release -y 先安装epel-release 再查看yum源中已经安装上了epel相关文件 中间省去了一些安 ...