问一下这题不能暴力求解吗
查看原帖
问一下这题不能暴力求解吗
1568393
KnownError楼主2024/12/3 23:29

rt,我写了一个暴力求解的程序,结果只有30分

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
bool a[10000001];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int j, k, t;
    for (int i = 1; i <= n; i++) {
        j = 1; k = i;
        while (j < k) {
            t = a[j];
            a[j] = a[k];
            a[k] = t;
            j++; k--;
        }
        for (int o = 1; o <= i; o++) {
            if (a[o] == 1) a[o] = 0;
            else a[o] = 1;
        }
    }
    for (int i = 1; i <= n; i++) cout << a[i] << ' ';
    return 0;
}
2024/12/3 23:29
加载中...