20求调!!!
查看原帖
20求调!!!
1490301
hzishi楼主2025/2/8 14:22

这个帮我改一下呗,,还有有没有回溯的算法??

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

bool q(const int& y, const int& t) {
    return y > t;
}

int main() {
    int tnt = 0;
    int s1, s2, s3, s4;
    int a1[60], a2[60], a3[60], a4[60];
    cin >> s1 >> s2 >> s3 >> s4;
    for (int i = 0; i < s1; i++) {
        cin >> a1[i];
    }
    for (int i = 0; i < s2; i++) {
        cin >> a2[i];
    }
    for (int i = 0; i < s3; i++) {
        cin >> a3[i];
    }
    for (int i = 0; i < s4; i++) {
        cin >> a4[i];
    }
    sort(a1, a1 + s1, q);
    sort(a2, a2 + s2, q);
    sort(a3, a3 + s3, q);
    sort(a4, a4 + s4, q);
    int c = 0;
    for (int i = 0; i < s1; i++) {
        if (s1 == 1) {
            tnt += a1[0];
        }
        else {
            c += a1[i];
        }
    }
    tnt += (c / 2) + (c % 2);
    c = 0;
    for (int i = 0; i < s2; i++) {
        if (s2 == 1) {
            tnt += a2[0];
        }
        else {
            c += a2[i];
        }
    }
    tnt += c / 2 + c % 2;
    c = 0;
    for (int i = 0; i < s3; i++) {
        if (s3 == 1) {
            tnt += a3[0];
        }
        else {
            c += a3[i];
        }
    }
    tnt += c / 2 + c % 2;
    c = 0;
    for (int i = 0; i < s4; i++) {
        if (s4 == 1) {
            tnt += a4[0];
        }
        else {
            c += a4[i];
        }
    }
    tnt += c / 2 + c % 2;
    cout << tnt;
    return 0;
}
2025/2/8 14:22
加载中...