top1编程
← 返回题目
题解

【基础】任务调度

1 条题解

  • 0
    @ 2026-7-29 0:15:36
    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    int main() {
        int n, R1;
        cin >> n >> R1;
        
        vector<int> a(n);
        // 生成R序列并计算a数组
        a[0] = (R1 % 100) + 1;
        int R_prev = R1;
        for (int i = 1; i < n; ++i) {
            int R_i = (R_prev * 6807 + 2831) % 20170;
            a[i] = (R_i % 100) + 1;
            R_prev = R_i;
        }
        
        // 按处理时间升序排序(短任务优先)
        sort(a.begin(), a.end());
        
        // 计算最小惩罚值
        long long penalty = 0;
        long long current_time = 0;
        for (int time : a) {
            current_time += time;
            penalty += current_time;
        }
        
        cout << penalty << endl;
        return 0;
    }
    
    • 1