7.28多校1004——模拟——Painter

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

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5326 5325 5324 5323 5322

/*
大意:R只能右下涂,B只能右上涂,G表示被两种颜色都涂了,问你至少涂多少次把它涂成这样,暴力枚举每种斜线从一个边界到另一个边界
做了半天最后被场外队友A了。
有好多要学习的地方
!!!看题仔细!!!
1.能简单开for循环的不要开while
2.ok判断能省很多代码量
3.想清楚dfs用来干什么~~不要乱开变得繁琐
4注意重复点不要多次进行DFS
*/
#include <cstdio>
#include <cstring>
#include <algorithm>

char map[55][55];
int f_left, f_right;
int cnt, n ,m;

bool ok(int x, int y)
{
    if(x < 0 || x >= n || y < 0 || y >= m)
        return false;
    return true;
}

void left(int x, int y)
{
    if(ok(x, y)){
        if(map[x][y] == ‘R‘ || map[x][y] == ‘G‘){
            if(f_left == 0){
                cnt++;
                f_left = 1;
            }
        }
        else f_left = 0;
    left(x + 1, y + 1);
    }
    return;
}

void right(int x, int y)
{
    if(ok(x, y)){
        if(map[x][y] == ‘B‘ || map[x][y] == ‘G‘){
            if(f_right == 0){
                cnt++;
                f_right = 1;
            }
        }
        else f_right = 0;
        right(x + 1, y - 1);
    }
    return ;
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        memset(map, 0, sizeof(map));
        cnt = 0;
        scanf("%d", &n);
        for(int i = 0 ; i < n; i++){
            scanf("%s", map[i]);
            m = strlen(map[i]);
        }
        for(int i = 0; i < n ; i++){
            f_left = 0;
            left(i, 0);
        }
        for(int i = 1; i < m ; i++){
            f_left = 0;
            left(0, i);
        }
        for(int i = 0; i < n; i++){
            f_right = 0;
            right(i,m-1);
        }
        for(int i = 0; i < m - 1 ; i++){
            f_right = 0;
            right(0, i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

  

时间: 2024-10-03 15:18:38

7.28多校1004——模拟——Painter的相关文章

2014/4/28 多校第九次

C:快速求N以内因数和,N以内互质数的和. 容斥版: 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #define maxn 1100000 5 #define LL long long 6 //N以内gcd(i,N)==1的i的和 7 using namespace std; 8 bool flag[maxn]; 9 int prim[maxn/3],cnt; 10 int pri

NYOJ-682 小媛在努力 (郑大第六届校赛 模拟)

链接:click here 题意: 描述 在多媒体数据处理中,数据压缩算法尤为重要.小媛上完课后就想自己发明一个数据压缩算法.她想呀想,终于想到一个方法.在多媒体数据中有很多数据都是重复的,所以她想把连续相同的数据用数据出现的次数和数据本身表示.例如:1 1 1 2 3 3 3 3 3  压缩后及为3 1 1 2 5 3(表示3个1,1个2和5个3).有想法后小媛就希望把它用代码实现了.但是大家都知道小媛现在整天都忙着苦B的复习考研,连电脑都摸不到.所以她希望作为ACMer的你帮她写一下. 输入

10.28&amp;29(NOIP模拟&amp;修正&amp;总结)

三道题: T1:约数的约数的个数和.数论.但是简单暴力A了. T2:前k大的(带权点ai与带权点bi的和)的和.二分.骗40. T3:三维空间内每次减少有与空点的点,前后左右相连,求最短时间减为空.dp每行每列每个点的最短路,每次自己-1,或等于相邻点,即从自己的时间和四周的点的时间+1取min,最后对于每个点取max即为最后消失时间.二十分暴力没写. 加强二分的练习,多思考,加强解题能力.

hdu 5327 Olympiad (多校联赛) ——模拟

here 题意:给你两个数,让你求出这两个数之间有多少个数,这个数满足他的每一位的数都不相同.例如 113 不满足 143 满足. Problem Description You are one of the competitors of the Olympiad in numbers. The problem of this year relates to beatiful numbers. One integer is called beautiful if and only if all

HDU 5336多校 十滴水模拟

Problem Description XYZ is playing an interesting game called "drops". It is played on a r?c grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is

hdu5319(2015多校3)--Painter(暴力,,,)

题目链接:点击打开链接 题目大意:一个画板,分成很多小格子,画家可以用红色R的笔'\',或者用蓝色B的笔'/',一个格子中如果画了红色和蓝色,那么会变成绿色G,对与一个格子来说一种颜色只能画一次,给出画完后的画板,问最少需要多少次才能画完. 直接暴力,有上到下遍历,尽量画更多的地方 注意:没有给出画板的长 #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; cha

hdu多校1004 Distinct Values

Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2635 Accepted Submission(s): 849 Problem Description Chiaki has an array of n positive integers. You are told some facts about the a

1.28 noip t1难度模拟赛

1 0pts 2 10pts 3 100pts 本想装个逼,从后面开始做,确实t3第一个AC,获得了紫色high light,BUT,第二题自己造的极端数据都过了,结果上讲台看,0分!!怎么可能?!检查了一下精度问题,没毛病啊,在最后两分钟发现我把题读错了--我以为必须要是升序的数列--被坑惨了,两分钟改了一下,得了10pts呵呵.t1没时间调了,死循环 t1迷宫 注意用dp做啊!dfs会爆,bfs懒得写-- #include <bits/stdc++.h> #define rep(i,a,b

【链表】【模拟】Codeforces 706E Working routine

题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别为(a,b)和(c,d),高度h,宽度w. (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) 题目思路: [链表][模拟] 这一看如果直接模拟的话时间复杂度是N*M*Q,肯定T了. 把矩阵看成链表,链表的方向有上下左右四种,其实每次交换两个子矩阵只改变的外围一圈的链表值,而内部的链