【題解】Google Kick Start 2020 Round F ATM Queue

【題目敘述】https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff48/00000000003f4ed8

#include <iostream>
#include <algorithm>
using namespace std;

int t, n, k, a[100005], o[100005];

bool cmp(int x, int y){
    if ((a[x]-1)/k+1 != (a[y]-1)/k+1) return (a[x]-1)/k+1 < (a[y]-1)/k+1;
    return x < y;
}

int main() {
    cin >> t;
    for (int Case = 1; Case <= t; Case++){
        cin >> n >> k;
        for (int i = 0; i < n; i++){
            cin >> a[i];
            o[i] = i;
        }
        sort(o, o+n, cmp);
        cout << "Case #" << Case << ":";
        for (int i = 0; i < n; i++){
            cout << " " << o[i]+1;
        }
        cout << "\n";
    }
}

分享本文 Share with friends