HDU 5319多校 模拟

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

扫描的时候把G看成B和R的组合。

遇到R或G的时候,向两个方向扫,同时把G变成B。

遇到B或G的时候,同理。

重复扫两遍

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#define ll long long
using namespace std;
char Map[60][60];
int vis[60][60];
int n,m;
int in(int x,int y)
{
    if(x>=0&&x<n&&y>=0&&y<m)
        return 1;
    return 0;
}
int sao(int xx,int yy,int c)
{
    int x,y;
    if(c==1)
    {
        x = xx;
        y = yy;
        while(1)
        {
            if(in(x+1,y+1)&&!vis[x+1][y+1])
            {
                if(Map[x+1][y+1]=='R')
                {
                    vis[x+1][y+1] = 1;
                    x++,y++;

                }
                else if(Map[x+1][y+1]=='G')
                {

                    Map[x+1][y+1]='B';
                     x++,y++;
                }
                else
                    break;
            }
            else
                break;
        }
        x = xx;
        y = yy;
        while(1)
        {
            if(in(x-1,y-1)&&!vis[x-1][y-1])
            {
                if(Map[x-1][y-1]=='R')
                {
                    vis[x-1][y-1] = 1;
                    x--,y--;
                }
                else if(Map[x-1][y-1]=='G')
                {

                    Map[x-1][y-1]= 'B';
                     x--,y--;
                }
                else
                    break;
            }
            else
                break;
        }
    }
    else
    {
        x = xx;
        y = yy;
        while(1)
        {
            if(in(x+1,y-1)&&!vis[x+1][y-1])
            {
                if(Map[x+1][y-1]=='B')
                {
                    vis[x+1][y-1] = 1;
                    x++,y--;
                }
                else if(Map[x+1][y-1]=='G')
                {

                    Map[x+1][y-1] ='R';
                    x++,y--;
                }
                else
                    break;
            }
            else
                break;
        }
        x = xx;
        y = yy;
        while(1)
        {
            if(in(x-1,y+1)&&!vis[x-1][y+1])
            {
                if(Map[x-1][y+1]=='B')
                {
                    vis[x-1][y+1] = 1;
                    x--,y++;

                }
                else if(Map[x-1][y+1]=='G')
                {

                    Map[x-1][y+1] ='R';
                    x--,y++;
                }
                else
                    break;
            }
            else
                break;
        }
    }

    return 0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%s",Map[i]);
        m = strlen(Map[0]);
        int sum = 0;
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(vis[i][j])
                    continue;
                if(Map[i][j]=='.')
                    continue;

                sum++;
                if(Map[i][j]=='R'||Map[i][j]=='G')
                {
                    if(Map[i][j]=='R')
                        vis[i][j] = 1;
                    else
                        Map[i][j]='B';
                    sao(i,j,1);
                }
                else if(Map[i][j]=='B'||Map[i][j]=='G')
                {
                    if(Map[i][j]=='B')
                        vis[i][j] = 1;
                    else
                        Map[i][j]='R';
                    sao(i,j,0);
                }
            }
        }
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(vis[i][j])
                    continue;
                if(Map[i][j]=='.')
                    continue;
                sum++;
                if(Map[i][j]=='R'||Map[i][j]=='G')
                {
                    if(Map[i][j]=='R')
                        vis[i][j] = 1;
                    else
                        Map[i][j]='B';
                    sao(i,j,1);
                }
                else if(Map[i][j]=='B'||Map[i][j]=='G')
                {
                    if(Map[i][j]=='B')
                        vis[i][j] = 1;
                    else
                        Map[i][j]='R';
                    sao(i,j,0);
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

时间: 2024-11-03 21:50:35

HDU 5319多校 模拟的相关文章

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

hdu 1175 连连看(模拟循环队列)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18149    Accepted Submission(s): 4741 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通过一条线连起来(这条

hdu 4893 (多校1007)Wow! Such Sequence!(线段树&amp;二分&amp;思维)

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

HDU 4608 I-number--简单模拟

I-number Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The I-number of x is defined to be an integer y, which satisfied the the conditions below: 1.  y>x; 2.  the sum of each digit of y(under base 10) is the multiple of 10; 3.  among all

hdu 4831 Scenic Popularity(模拟)

题目链接:hdu 4831 Scenic Popularity 题目大意:略. 解题思路:对于休闲区g[i][0]和g[i][1]记录的是最近的两个景点的id(只有一个最近的话g[i][1]为0),对于景点来说,g[i][0]为-1(表示该id对应的是景点),g[i][1]为该景点的热度值.主要就是模拟,注意一些细节就可以了. #include <cstdio> #include <cstring> #include <cstdlib> #include <alg

hdu 3125 Slash(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3125 Problem Description The American English slash (/) is a punctuation mark. In the early modern period, in the Fraktur script, which was widespread through Europe in the Middle Ages, one slash(/) repr

hdu 4858 项目管理(vector模拟)

# include <stdio.h> # include <algorithm> # include <string.h> # include <vector> # define N 100005 using namespace std; vector<int>g[N]; int node[N]; int slove(int x) { int sum=0,i; for(i=0;i<g[x].size();i++) { sum+=node[

hdu 4941 STL HASH 模拟

http://acm.hdu.edu.cn/showproblem.php?pid=4941 比赛的时候现学的map的find...以前都是用下标做的,但是map用下标查询的话,如果查询的元素不存在,会插入一个新的元素. 贴一个map查找元素找到和找不到的模板 map<pair<int,int>,int>::iterator it=poshash.find(tmppos);//pair<int,int>poshash; int pp; if(it == poshash.

HDU 4022 Bombing STL 模拟题

手动模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define N 10100 #define inf 1000000010 map<