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 ...
随机推荐
- VirtualBox Networking Model
- Swift 中的值类型与引用类型
顶级修饰 次级修饰 赋值类型 存储类型 值类型 值类型 深拷贝 栈 值类型 引用类型 浅拷贝 堆 引用类型 值类型 浅拷贝 堆 引用类型 引用类型 浅拷贝 堆 复合引用类型会改变内部值类型的存储行 ...
- zuul 网关
1.网关的作用 网关可以拦截客户端所有请求,对该请求进行权限控制,负载均衡.日志管理.接口调用监控等操作. 1)网关对所有服务会话进行拦截 2)网关安全控制,统一异常处理,XXS.SQL注入 3)权限 ...
- 异步编程when.js
when.js很小,压缩后只有数kb,gzip后的大小几乎可以忽略.在Node和浏览器环境里都可以使用when.js 首先,我们看一小段代码: var getData = function(callb ...
- zabbix4.2学习笔记--监控tomcat
zabbix提供了一个java gateway的应用去监控jmx(Java Management Extensions,即Java管理扩展)是一个为应用程序.设备.系统等植入管理功能的框架 环境 主机 ...
- 扫黑除恶Team第四次团队作业
二.博客撰写要求 文章开头给出团队序号,开发的软件名称,仓库地址. 给出完成本次冲刺需要做的事情(Sprint Backlog)及相应说明. 本次冲刺总结. 三.评分规则 注意:本次作业总分61分.发 ...
- 梯度提升决策树(GBDT)与XGBoost、LightGBM
今天是周末,之前给自己定了一个小目标:每周都要写一篇博客,不管是关于什么内容的都行,关键在于总结和思考,今天我选的主题是梯度提升树的一些方法,主要从这些方法的原理以及实现过程入手讲解这个问题. 本文按 ...
- mxnet.base.MXNetError: src/imperative/./imperative_utils.h:70: Check failed: inputs[i]->ctx().dev_mask() == ctx.dev_mask() (1 vs. 2)
mxnet 训练错误: mxnet.base.MXNetError: [14:42:22] src/imperative/./imperative_utils.h:70: Check failed: ...
- 初识Python(windows)——下载、安装、使用
Table of Contents 1. Why is Python 1.1. Python和R 2. python的下载与安装 2.1. python的版本选择 2.2. python的下载 2.3 ...
- ubuntu(linux)占领小米平板2(mipad2)
昨天 2014年,媳妇坐月子,给媳妇买了mi6和一个小米平板2(16G).是我们人生拥有的第一个平板,激动不已. 买之前看了小米平板1的口碑不错,arm构架,NVIDIA的主板好像,图形处理做得当然没 ...