-
Notifications
You must be signed in to change notification settings - Fork 1
/
UVa 410.cpp
69 lines (48 loc) · 1.15 KB
/
UVa 410.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define iter(i,a,b) for(int i = (a) ; i < (b) ; i++)
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> iii;
typedef vector <pii> vii;
#define INF 1000000000
#define MAXX 1000
int main(){
//READ("UVa 410.txt");
int tc, case_no = 0, c, s;
while(scanf("%d %d", &c, &s) != EOF){
vector <int> cm(2 * c, 0);
int total_cm = 0;
rep(i, s){
scanf("%d", &cm[i]);
total_cm += cm[i];
}
double avg_m = (double)total_cm / (double)c;
sort(cm.begin(), cm.end());
int res_cm[c];
mem(res_cm, 0);
printf("Set #%d\n", ++case_no);
rep(i, c){
printf(" %d:", i);
if(cm[i]){
printf(" %d", cm[i]);
res_cm[i] += cm[i];
}
if(cm[(2 * c) - i - 1]){
printf(" %d", cm[(2 * c) - i - 1]);
res_cm[i] += cm[(2 * c) - i - 1];
}
printf("\n");
}
double imbalance = 0.0;
rep(i, c){
imbalance += abs(res_cm[i] - avg_m);
}
printf("IMBALANCE = %0.5lf\n\n", imbalance);
}
return 0;
}