只能过#1,#3,萌新求助
查看原帖
只能过#1,#3,萌新求助
305770
claran_ran_away楼主2022/9/14 21:18
#include <bits/stdc++.h>
using namespace std;

int n,m,ans = 0;
char check[3] = {'W','B','R'};

int cover(int line,char smp[51][51]){
	int num = 0,count = 0;
	for(int k = line;k < n;k++){
		for(int l = 0;l < m;l++){
			if(k <= line + 2){ 
				if(smp[k][l] != check[count]) {
					//cout << k << " " << l << " " << smp[k][l] << " " << check[count] << " ";
					num++;
				}
			} 
			else if(k > line + 2){ 
			//cout << "here";
				if(smp[k][l] != check[2]){
					//cout << k << " " << l << " " << smp[k][l] << " ";
					num++;
				}
			} 
		}
		count++;
		//cout << " k = " << k << endl; 
	} 
	return num;
}

int main(){
	cin >> n >> m;
	char mp[51][51];
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m ;j++){
			cin >> mp[i][j];
		}
	} 
	for(int i = 0;i < n - 2;i++){
		//cover(i,mp);
		//cout << endl << "again" << endl; 
		if(i == 0){
		    ans = cover(i,mp);
		} 
		else if(ans > cover(i,mp)){
			//cout << "here ";
			ans = cover(i,mp);
		}
		//cout << endl << ans << endl;
	} 
	cout << ans;
	return 0;
}
/*
5
5
WWWWW
BBBBB
RRRRR
GGGGG
GGGGG
*/
2022/9/14 21:18
加载中...