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 ...
随机推荐
- vultr系统重建
vultr服务器重启后ssh连接不上,view console只能guest登录,遍寻方法,无解,无奈重装系统. 服务器地址:Los Angeles 系统: Ubuntu 14.04 x64 用户:r ...
- 谈谈Java中的集合
对于集合类,主要需要掌握的就是它的内部结构,以及遍历集合的迭代模式. 接口:Collection Collection是最基本的集合接口,一个Collection代表一组Object,即Collect ...
- iOS截取特定的字符串(正则匹配)
有时候我们会有需求从一个字符串中截取其他的字符串,根据情况的不同,我们来分析几种方法~~ 一. 固定长度字符串中截取固定位置长度的字符串 // 这是比较简单的一种情况:比如截取手机号的后4位 let ...
- CREATE TABLE AS - 从一条查询的结果中创建一个新表
SYNOPSIS CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name [ (column_name [, ...] ...
- CAD控件,CAD插件使用教程:Android开发使用控件--开发环境的搭建
Android开发使用控件入门--环境搭建 2014-12-24 09:57 14人阅读 评论(0) 收藏 编辑 删除 CAD控件.CAD三维控件,手机 ...
- 实现UAC对话框效果
设置桌面全屏: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_ ...
- Windows文件自删除的两种方法
可执行模块的自删除技术已经被讨论的很多, 有很多极富创意的思路和想法被提出, 但有些似是而非的方案往往使人误入歧途. 举个例子来说, 很多文章认为下面的一小段代码可以实现自删除:void main(v ...
- 【MSSQL】MDF、NDF、LDF文件的含义
[MSSQL]MDF.NDF.LDF文件的含义 2012-09-03 15:32:56| 分类: SQL数据库|举报|字号 订阅 MDF是 primary data file 的缩写:NDF ...
- sqlite3接口简要说明
本文介绍一下SQLite C/C++接口. 早期的SQLite C/C++接口只有5个接口函数, 很容易学习. 新版本的SQLite新增了很多功能, 目前大概有185个API接口.本文介绍一些核心的A ...
- 2019浙师大校赛(浙大命题)(upc复现赛)总结
2019浙师大校赛(浙大命题)(upc复现赛)总结 早上九点开始.起得迟了,吃了早饭慌慌张张跑过去,刚到比赛就开始了. 开始分别从前往后和从后往前看题,一开始A题,第一发WA,第二次读题发现漏看了还有 ...