0%

APCS-流量計算

Link

https://zerojudge.tw/ShowProblem?problemid=f605

Code

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

int calc(int s,int e,int f){
    int total = 0;
    if(s==e){
        return f;
    } else {
        if(f<=1000) {
            return f*3;
        } else {
            return (f-1000)*2+3000;
        }
    }
}

int main() {
    int s,c,n;
    int Q[100][100];

    cin >> s >> c >> n;
    for(int i=0;i<s;i++){
        for(int j=0;j<c;j++){
            cin >> Q[i][j];
        }
    }
    vector<int>cc;
    for(int i=0;i<n;i++){
        int v[100][100];
        memset(v, 0, sizeof(v));
        set<pair <int, int>> se;

        for(int j=0;j<s;j++){
            int _c;cin >> _c;
            for(int k=0;k<c;k++){
                v[_c][k] += Q[j][k];
                //cout << "Start: " << _c << " End: " << k << " Flow: " << Q[j][k] << " Cnt: " << v[_c][k] <<  endl;
                se.emplace(make_pair(_c,k));
            }
        }

        int total =0;
        for(auto &x: se){
            total += calc(x.first, x.second, v[x.first][x.second]);
            //cout << "Start: " << x.first << " End: " << x.second << " Flow: " << v[x.first][x.second] << " Total: " << total <<  endl;
        }


        //cout << total << endl;
        cc.emplace_back(total);
        // end 方案
    }
    sort(cc.begin(), cc.end());
    cout << cc[0] << endl;


    return 0;
}