forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1000.cpp
75 lines (70 loc) · 1.17 KB
/
1000.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
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
typedef struct
{
int NO, ac[30], dc[30], w;
} Cas;
Cas cas[21];
int len;
int N, K, Ar;
int arr[30][30];
int cmp(const void *a, const void *b)
{
Cas *pa = (Cas *)a, *pb = (Cas *)b;
if (pa->w == pb->w)
{
return pa->NO - pb->NO;
}
else
{
return pa->w - pb->w;
}
}
int main()
{
int i, j, k, D, flow;
while (scanf("%d", &N), N != 0)
{
memset(arr, 0, sizeof(arr));
memset(cas, 0, sizeof(cas));
len = 0;
for (i = 0; i < N; i++)
{
scanf("%d%d", &Ar, &K);
for (j = 0; j < K; j++)
{
scanf("%d%d", &D, &flow);
arr[Ar][D] = flow;
}
}
while (scanf("%d", &K), K != 0)
{
cas[len].NO = K;
cas[len].w = 0;
for (i = 0; i < N; i++)
{
scanf("%d", &cas[len].ac[i]);
}
for (i = 0; i < N; i++)
{
scanf("%d", &cas[len].dc[i]);
}
cas[len].w = 0;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
cas[len].w += arr[cas[len].ac[i]][cas[len].dc[j]] * (1 + abs(i - j));
}
}
len++;
}
qsort(cas, len, sizeof(cas[0]), cmp);
printf("Configuration Load\n");
for (i = 0; i < len; i++)
{
printf("%5d %d\n", cas[i].NO, cas[i].w);
}
}
return 0;
}