HDU 5319 Painter (模拟 脑洞题)

Painter

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 133    Accepted Submission(s): 67

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

2015 Multi-University Training Contest 3

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319

题目大意:刷墙,只能按两个斜45度刷,一个是红色,一个是蓝色,红遇蓝变绿,每个格子同种颜色只刷一次,每次刷必须是连续的一段,问答案目标状态最少刷几次

题目分析:按两个方向枚举,\这种样子刷,若当前点是红或绿且斜前一个点不是红且不是绿,则必然要刷一次,同理/这样刷时也判断一下,可是为什么这样算出来就是最小的呢,因为我只在必须要刷的时候才刷,所以显然这样就是最优的

#include <cstdio>
#include <cstring>
char s[55][55];

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        for(int i = 1; i <= n; i++)
            scanf("%s", s[i] + 1);
        int m = strlen(s[1] + 1);
        int ans = 0;
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                if(s[i][j] == 'R' || s[i][j] == 'G')
                    if(!(s[i - 1][j - 1] == 'R' || s[i - 1][j - 1] == 'G'))
                        ans ++;
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                if(s[i][j] == 'B' || s[i][j] == 'G')
                    if(!(s[i - 1][j + 1] == 'B' || s[i - 1][j + 1] == 'G'))
                        ans ++;
        printf("%d\n", ans);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-07 23:34:49

HDU 5319 Painter (模拟 脑洞题)的相关文章

HDU 5319 Painter (模拟)

题意:一个画家画出一张,有3种颜色的笔,R.G.B.R看成'\',B看成'/',G看成这两种的重叠(即叉形).给的是一个矩阵,矩阵中只有4种符号,除了3种颜色还有'.',代表没有涂色.问最小耗费多少笔即可画成这副图? 思路:最小耗费就是斜着的可以一笔搞定,但是如果中间隔着'.'或者其他一种形状,则不能一笔,要变两笔.主要麻烦在矩阵不是正方形,而可能是长方形.其实只要按照其画法,从左上往右下方向画,逐个条斜线扫描即可.另一个方向'/'也是如此. 我看到模拟本来就不想敲,扫两遍矩阵,用了vector

hdoj 5319 Painter(模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 思路分析:假设颜色R表示为1,颜色B表示为2,颜色G表示为3,因为数据量较小,采用暴力解法即可,即每次扫描对角线,看每条对角线需要画多少笔,统计所有对角线的笔数和即可: 代码如下: #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int MAX_N

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 Problem Description Mr. Hdu is an painter, as we all know, painters need ideas to innovate , one day,

hdu 5319 Painter

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 题意:给你一个正方形,一把刷子,两种刷色法. ' \' 表示沿对角刷成红色,"/" 表示沿对角刷成蓝色.蓝色红色交叉形成绿色: 问最少刷几次形成如图图案. 解法:从上到下未被刷过就直接刷. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h&

模拟+思维 HDOJ 5319 Painter

题目传送门 1 /* 2 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 3 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最小的,脑洞大 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 c

HDU 5319(2015多校3)-Painter(dfs)

题目地址:HDU 5319 题意:给一个图n*m,原来全是点('.'). 现在要把图染成已给出的样子. 要求当是'\'的情况只用红色,是'/'的情况只用蓝色,当一个格子同时被红色和蓝色染得时候变成绿色.(每个格子只画一次). 思路:这题只要模拟一下刷的过程就行了,如果出现了R,就刷R刷到底,出现B就刷B,出现G就左右各刷一次. #include <stdio.h> #include <math.h> #include <string.h> #include <st

[BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)

Task schedule Problem Description 有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务. 有m个询问,每个询问有一个数字q,表示如果在q时间有一个工作表之外的任务请求,请计算何时这个任务才能被执行. 机器总是按照工作表执行,当机器空闲时立即执行工作表之外的任务请求. Input 输入的第一行包含一个整数T, 表示一共有T组测试数据. 对于每组测试数据: 第一行是两个数字n, m,表示工作表里面有n个任务,

HDOJ 2317. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of

HDU 4893 线段树裸题

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2512    Accepted Submission(s): 751 Problem Description Recently, Doge got a funny birthday present from his new friend, Pro