其他分享
首页 > 其他分享> > P1223 排队接水

P1223 排队接水

作者:互联网

// Problem: P1223 排队接水
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1223
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

template<class T>
void debugVector(const T &a) {
    cout << "[ ";
    for (size_t i = 0; i < a.size(); ++i) {
        cout << a[i] << (i == a.size() - 1 ? " " : ", ");
    }
    cout << "]" << endl;
}

template<class T>
void debugMatrix2(const T &a) {
    for (size_t i = 0; i < a.size(); ++i) {
        debugVector(a[i]);
    }
}

template<class T>
using matrix2 = vector<vector<T>>;

template<class T>
vector<vector<T>> getMatrix2(size_t n, size_t m, T init = T()) {
    return vector<vector<T>>(n, vector<T>(m, init));
}

template<class T>
using matrix3 = vector<vector<vector<T>>>;

template<class T>
vector<vector<vector<T>>> getMatrix3(size_t x, size_t y, size_t z, T init = T()) {
    return vector<vector<vector<T>>>(x, vector<vector<T>>(y, vector<T>(z, init)));
}

vector<int> genBigInteger(string a) {
    vector<int> res;
    for (int i = a.size() - 1; i >= 0; --i) {
        res.push_back(a[i] - '0');
    }
    return res;
}

void printBigInteger(vector<int> a) {
    for (size_t i = a.size() - 1; i >= 0; --i) {
        cout << a[i];
    }
}

vector<int> addBigInteger(vector<int> a, vector<int> b) {
    vector<int> res;
    int pre = 0;
    for (size_t i = 0; i < a.size() || i < b.size() || pre; ++i) {
        if (i < a.size()) pre += a[i];
        if (i < b.size()) pre += b[i];
        res.push_back(pre % 10);
        pre /= 10;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<pair<int, int>> info(n);
    for (int i = 0; i < n; ++i) {
        cin >> info[i].first;
        info[i].second = i + 1;
    }
    
    sort(info.begin(), info.end());
    
    long long res = 0, nowt = 0;
    for (int i = 0; i < n; ++i) {
        printf("%d ", info[i].second);
        res += nowt;
        nowt += info[i].first; 
    }
    printf("\n%.2f\n", res * 1.0 / n);
    return 0;
}

标签:info,pre,int,res,排队,vector,P1223,size
来源: https://www.cnblogs.com/pannnn/p/15981251.html