devc++国旗代码
时间: 2023-10-26 09:05:45 浏览: 105
devc的国旗代码是给定一个棋盘状的布,分成了n行m列的格子,每个格子是白色、蓝色或红色之一。国旗代码的目标是在一些格子上涂颜料,使其满足国旗的规则。具体的代码如下:
#include <bits/stdc++.h>
using namespace std;
int m, n, minn = 1410065407;
char a[105][105];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n - 2; i++) {
for (int j = i + 1; j <= n - 1; j++) {
int sum = 0;
for (int k = 1; k <= i; k++) {
for (int w = 1; w <= m; w++) {
if (a[k][w] != 'W') {
sum++;
}
}
}
for (int k = i + 1; k <= j; k++) {
for (int w = 1; w <= m; w++) {
if (a[k][w] != 'B') {
sum++;
}
}
}
for (int k = j + 1; k <= n; k++) {
for (int w = 1; w <= m; w++) {
if (a[k][w] != 'R') {
sum++;
}
}
}
minn = min(sum, minn);
}
}
cout << minn;
return 0;
}
阅读全文