求大神解答!
  • 板块P3392 涂国旗
  • 楼主xiaoni0v0
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/23 20:28
  • 上次更新2023/11/2 18:27:05
查看原帖
求大神解答!
852826
xiaoni0v0楼主2023/9/23 20:28

山穷水尽了,不知道我这破代码有啥问题。自己造了几组数据试着“貌似”没毛病,但也不至于全都WA吧。。。

#include <bits/stdc++.h>
using namespace std;

int N, M, distc[3][50], n_op, min_op = 1 << 30;
char _in;

/* W: 0
 * B: 1
 * R: 2
 */

int main()
{
    // 输入
    cin >> N >> M;
    getchar();
    if (N < 3) // 特殊情况特殊处理
    {
        cout << 0 << endl;
        return 0;
    }

    // compute distance
    for (int row = 0; row < N; row++)
    {
        for (int col = 0; col < M; col++)
        {
            _in = getchar();
            if (_in != 'W')
                distc[0][row]++;
            if (_in != 'B')
                distc[1][row]++;
            if (_in != 'R')
                distc[2][row]++;
        }
        getchar();
    }

    // start enum
    for (int start = 1; start < N - 1; start++)
    {
        for (int end = start; end < N - 1; end++)
        {
            n_op = 0;
            for (int row = 0; row < start; row++)
                n_op += distc[0][row];
            for (int row = start; row <= end; row++)
                n_op += distc[1][row];
            for (int row = end + 1; row < N; row++)
                n_op += distc[2][row];
            if (n_op < min_op)
                min_op = n_op;
        }
    }

    // 输出
    cout << min_op << endl;

    return 0;
}
2023/9/23 20:28
加载中...