题解:P13463 [GCJ 2008 #1C] Text Messaging Outrage
Peruere_Arlecchino · · 题解
解决这个问题,可以通过将字母按出现频率从高到低排序,并再依次分配到按键上,使第
code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
for (int v = 1; v <= N; ++v) {
int P, K, L;
cin >> P >> K >> L;
vector<int> c(L);
for (int i = 0; i < L; ++i) {
cin >> c[i];
}
sort(c.rbegin(), c.rend());
long long g = 0;
int x;
for (x = 0; x < L; ++x) {
int o = (x / K) + 1;
g += (long long)c[x] * o;
}
cout << "Case #" << v << ": " << g << endl;
}
return 0;
}
求赞求过。