hdu 5319 Painter(杭电多校赛第三场)
题目链接: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
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.
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.
description.
6
#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(杭电多校赛第三场)的更多相关文章
- hdu 5326 Work(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 5373 The shortest problem(杭电多校赛第七场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 The shortest problem Time Limit: 3000/1500 MS (J ...
- hdu 5328 Problem Killer(杭电多校赛第四场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...
- HDU 5762 Teacher Bo (鸽笼原理) 2016杭电多校联合第三场
题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<1 ...
- HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场
题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过l ...
- HDU 5754 Life Winner Bo (各种博弈) 2016杭电多校联合第三场
题目:传送门 题意:一个国际象棋棋盘,有四种棋子,从(n,m)走到(1,1),走到(1,1)的人赢,先手赢输出B,后手赢输出G,平局输出D. 题解:先把从(n,m)走到(1,1)看做是从(1,1)走到 ...
- HDU 4627 The Unsolvable Problem 杭电多校联赛第三场1009 数学题
题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这 ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场
题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...
随机推荐
- pixi.js tools
pixi群 881784250 Awesome pixi.js tools A list of useful libs/resources/tools for renowned html5 rende ...
- PHP对象的复制
对象的复制(克隆) $obj1 = new A(); $obj1->p1 = 11; $obj2 = $obj1; //值传递 //则,现在有几个对象?——1个对象! 当然: $obj3 ...
- MySQL专题3 SQL 优化
这两天去京东面试,面试官问了我一个问题,如何优化SQL 我上网查了一下资料,找到了不少方法,做一下记录 (一). 首先使用慢查询分析 通过Mysql 的Slow Query log 可以找到哪些SQ ...
- 在dbgrid中如何多行选中记录(ctl与shift均可用)
在dbgrid中如何多行选中记录(ctl与shift均可用),设置dbgrid的dgmultiselect为true,只有ctl好用而shift不好用,如何使shift也好用 Dbgrid源代码:pr ...
- Linux的cut命令
cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的. (1)其语法格式为:cut [-bn] [file] 或 cut ...
- [六]SpringBoot 之 连接数据库(mybatis)
在进行配置之前首先要了解springboot是如何使用纯java代码方式初始化一个bean的 以前的版本是在xml中使用beans标签,在其里面配置bean,那么纯Java代码怎么实现呢? 答案就是使 ...
- (转)解决点击a标签返回页面顶部的问题
本文转载至http://www.cnblogs.com/chenluomenggongzi/p/5950670.html 1 <!DOCTYPE html> 2 <html lang ...
- C++解析(20):智能指针与类型转换函数
0.目录 1.智能指针 2.转换构造函数 3.类型转换函数 4.小结 1.智能指针 内存泄漏(臭名昭著的Bug): 动态申请堆空间,用完后不归还 C++语言中没有垃圾回收机制 指针无法控制所指堆空间的 ...
- 【刷题】清橙 A1295 necklace
试题来源 清华大学2011年百名信息学优秀高中学子夏令营 问题描述 有人打算送给你一条宝石项链,包含了N颗五颜六色(一共有M种颜色)的宝石.因为本问题中你只关心每个宝石的颜色,而且项链现在两头还没有接 ...
- [FJWC2018]全排列 DP
题面 题面 题解 (表示第一段文字导致我在考场上没看懂题--因为我以为这个定义是定义在整个排列上的,所以相似 = 相同.结果其实是可以应用在一个区间上--) 首先我们发现,2个区间相似,其实就是离散化 ...