题意:
给你一个空白的图,你可以随意选几个连续的斜格子画线,红色只能\着画,蓝色只能/着画,每个格子只能被红线和蓝线涂一次,如何一个格子既有红色又有蓝色,就变成了绿色,给定你一个图,问至少画几条线。
解析:
刚刚开始题目看错了,卡了好久,水题,直接模拟。
my code
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 55;
int red[N][N], blue[N][N];
char grid[N][N];
int n, m;
void init() {
    memset(red, 0, sizeof(red));
    memset(blue, 0, sizeof(blue));
}
void moveRed(int x, int y) {
    if(x < 0 || x >= n || y < 0 || y >= m) return ;
    if(red[x][y] == 0) return ;
    red[x][y] = 0;
    moveRed(x+1, y+1);
}
void moveBlue(int x, int y) {
    if(x < 0 || x >= n || y < 0 || y >= m) return ;
    if(blue[x][y] == 0) return ;
    blue[x][y] = 0;
    moveBlue(x+1, y-1);
}
int calRed() {
    int ret = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(red[i][j]) {
                moveRed(i, j);
                ret++;
            }
        }
    }
    return ret;
}
int calBlue() {
    int ret = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(blue[i][j]) {
                moveBlue(i, j);
                ret++;
            }
        }
    }
    return ret;
}
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &n);
        init();
        for(int i = 0; i < n; i++) {
            scanf("%s", grid[i]);
            m = strlen(grid[i]);
            for(int j = 0; j < m; j++) {
                if(grid[i][j] == 'R')
                    red[i][j]++;
                else if(grid[i][j] == 'B')
                    blue[i][j]++;
                else if(grid[i][j] == 'G'){
                    red[i][j]++;
                    blue[i][j]++;
                }
            }
        }
        printf("%d\n", calRed() + calBlue());
    }
    return 0;
} 
                   
                   
                   
                   
                             本文介绍了一种使用模拟算法解决特定网格染色问题的方法。该问题要求在一个空白图中绘制斜线来覆盖标记为红色、蓝色或绿色的单元格,通过最少次数的绘制使所有指定颜色的单元格被正确覆盖。
本文介绍了一种使用模拟算法解决特定网格染色问题的方法。该问题要求在一个空白图中绘制斜线来覆盖标记为红色、蓝色或绿色的单元格,通过最少次数的绘制使所有指定颜色的单元格被正确覆盖。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   945
					945
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            