HDU 5319 Painter(枚举)
Painter
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 745 Accepted Submission(s): 345
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.
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.
2
4
RR.B
.RG.
.BRR
B..R
4
RRBB
RGGB
BGGR
BBRR
3
6
pid=5324" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5324
5322 5321 5320#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; char pp[91][91];
int v[91][91];
int n,m; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int ans = 0;
int k;
memset(v,0,sizeof(v));
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",pp[i]);
k = strlen(pp[i]); }
for(int i=0;i<n;i++)
{
for(int j=0;j<k;j++)
{
if((pp[i][j] == 'R' || pp[i][j] == 'G')&& v[i][j] == 0)
{
int ii = i,jj = j;
while((pp[ii][jj] == 'R' || pp[ii][jj] == 'G') && v[ii][jj] == 0)
{
v[ii][jj]++;
//printf("v[%d][%d] = %d\n",ii,jj,v[ii][jj]);
ii = ii + 1;
jj = jj + 1;
if(ii>=n || jj>=k)
{
break;
}
}
ans++;
}
}
}
//printf("ans = %d\n",ans);
for(int i=0;i<n;i++)
{
for(int j=0;j<k;j++)
{
if((pp[i][j] == 'B'&&v[i][j] == 0) || (pp[i][j] == 'G' && v[i][j] == 1))
{
int x = i;
int y = j;
//printf("x = %d y = %d\n",x,y);
while((pp[x][y] == 'B' && v[x][y] == 0) || (pp[x][y] == 'G' && v[x][y] == 1))
{
v[x][y]++;
//printf("v[%d][%d] = %d\n",x,y,v[x][y]);
x = x + 1;
y = y - 1;
if(x>=n || y<0)
{
break;
}
}
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}
HDU 5319 Painter(枚举)的更多相关文章
- hdu 5319 Painter(杭电多校赛第三场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5319 Painter (模拟)
题意: 一个画家画出一张,有3种颜色的笔,R.G.B.R看成'\',B看成'/',G看成这两种的重叠(即叉形).给的是一个矩阵,矩阵中只有4种符号,除了3种颜色还有'.',代表没有涂色.问最小耗费多少 ...
- HDU 5319 Painter
题意:红色从左上向右下涂,蓝色从右上向左下涂,既涂红色又涂蓝色就变成绿色,问最少涂几下能变成给的图. 解法:模拟一下就好了,注意细节. 代码: #include<stdio.h> #inc ...
- 模拟+思维 HDOJ 5319 Painter
题目传送门 /* 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最 ...
- hdu 2489(枚举 + 最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2489 思路:由于N, M的范围比较少,直接枚举所有的可能情况,然后求MST判断即可. #include ...
- hdu 3118(二进制枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边, ...
- hdoj 5319 Painter(模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 思路分析:假设颜色R表示为1,颜色B表示为2,颜色G表示为3,因为数据量较小,采用暴力解法即可, ...
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 5319
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
随机推荐
- Node.js+Express+MVC+Mysql小白创建新项目
1.打开CMD命令窗口,这一步不会的,回家休息,不要看了 2.npm install -g yo 等待时间看个人电脑情况. 如果没有npm命令,建议先安装npm ,npm安装介绍:https://d ...
- 在Eclipse中用Maven打包jar包--完整版
将本地的jar导入到maven本地库中 <!--手动加入库中 --><!-- mvn install:install-file -DgroupId=org.apache.Hadoop ...
- new Buffer 生成二进制数据
node编辑环境下: > new Buffer("admin")<Buffer 61 64 6d 69 6e> 通过post请求,服务端接收到是流数据,必须把流数 ...
- webpack遇见的坑:Please install 'webpack-cli' in addition to webpack itself to use the CLI.
webpack-cli没被找到: 在webpack4.0之后,需要全局安装webpack-cli, 在全局安装webpack之后,cnpm i webpack-cli -g 在局部使用webpack时 ...
- Java 获取当前时间最近12个月(字符串)
/** * 获取当前系统时间最近12月的年月(含当月) * 2018-04~2019-03 */ public String getLatest12Month(Date date){ Calendar ...
- vue全选与反选以及通过使用如何filter删除数据
在vue学习经常遇到的一些基本问题,下面是购物车里面的部分功能,分享给初学者,直接上源码: <!DOCTYPE html><html> <head> <met ...
- C++命名空间、标准库(std,全局命名空间)
背景 别人遇到的问题: C++ 全局变量不明确与 using namespace std 冲突 我遇到的问题与他相似,函数调用冲突 using namespace std; class compare ...
- mycat——未完成
https://www.cnblogs.com/joylee/p/7513038.html https://blog.csdn.net/wrs120/article/details/80417345 ...
- linux 批量修改文件名 文件名只保留部分,去掉部分
问题:linux系统中文件名包含中文,导致页面访问不了文件.就是上条博客中的解决方法二遗留问题. 文件名中有以下格式:TC2_诺而达铜管(中山)有限公司.pdf ,要改为TC2.pdf,去掉中文部分 ...
- 19Spring返回通知&异常通知&环绕通知
在前置通知和后置通知的基础上加上返回通知&异常通知&环绕通知 代码: package com.cn.spring.aop.impl; //加减乘除的接口类 public interfa ...