#include<iostream> #include<cstdio> #include<utility> #include<cmath> #include<cstring> #include<vector> #include<algorithm> #define db(a) cout << #a << " = " << a << endl using namespace std; bool cmp(const pair<int, int>& a, const pair<int, int>& b) { return a.first <= b.first; } bool cmp_list(const vector< pair<int, int> >& a, const vector< pair<int, int> >& b) { int min_a = 20, min_b = 20; for (int i = 0; i < a.size(); i++) { if (a[i].second < min_a) min_a = a[i].second; } for (int i = 0; i < b.size(); i++) { if (b[i].second < min_b) min_b = b[i].second; } return min_a <= min_b; } int main() { int c, s, cont = 0; #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif while (scanf("%d %d", &c, &s) !=EOF) { vector< pair<int, int> > lista(2 * c); double A = 0; for (int i = 0; i < s; i++) { scanf("%d", &lista[i].first); A += lista[i].first; lista[i].second = i; } for (int i = s; i < 2 * c; i++) { lista[i].second = i; } A /= c; sort(lista.begin(), lista.end(), cmp); double res = 0; vector< vector< pair<int, int> > > elementos(c); for (int i = 0; i < c; i++) { res += fabs(lista[i].first + lista[2 * c - i - 1].first - A); if (lista[i].second < lista[2 * c - i - 1].second) { elementos[i].push_back(lista[i]); elementos[i].push_back(lista[2 * c - i - 1]); } else { elementos[i].push_back(lista[2 * c - i - 1]); elementos[i].push_back(lista[i]); } } printf("Set #%d\n", ++cont); int n = elementos.size(); sort(elementos.begin(), elementos.end(), cmp_list); for (int i = 0; i < c; i++) { printf("% d:", i); for (int j = 0; j < elementos[i].size(); j++) { if (elementos[i][j].first != 0) printf(" %d", elementos[i][j].first); } puts(""); } printf("IMBALANCE = %.5f\n\n", res); } return 0; }
miércoles, 3 de octubre de 2012
410 - Station Balance, uva, solution
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario