-
Notifications
You must be signed in to change notification settings - Fork 5
/
UVA-815.cpp
67 lines (59 loc) · 1.22 KB
/
UVA-815.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
#include<stdio.h>
#include<stdlib.h>
int arr[1000];
int m,n, water;
double level;
int cmp(const void *i , const void *j) {
return *(int *)i - *(int *)j;
}
double culLevel(int i) {
return (double)water / (i * 100) + level;
}
int cul() {
int levelt = arr[0];
level = levelt;
if(water <= 0) {
return 0;
}
int i;
for(i = 1; i < m * n; ++i) {
if(arr[i] == levelt) {
continue;
}
if(water == i * (arr[i] - levelt) * 100) {
levelt = arr[i];
level = levelt;
return i;
} else if(water > i * (arr[i] - levelt) * 100) {
water -= i * (arr[i] - levelt) * 100;
levelt = arr[i];
level = levelt;
} else {
level = culLevel(i);
return i;
}
}
level = culLevel(m * n);
return m * n;
}
int main() {
int count = 0;
int i, j, k;
int region;
while(scanf("%d %d", &m ,&n) == 2 && m != 0) {
for(i = 0; i < m; ++i) {
for(j = 0; j < n; ++j) {
scanf("%d", &arr[i*n + j]);
}
}
scanf("%d", &water);
qsort(arr, m*n, sizeof(int), cmp);
region = cul();
// if(count != 0) { putchar('\n'); }
printf("Region %d\n", ++count);
printf("Water level is %.2lf meters.\n", level);
printf("%.2lf percent of the region is under water.\n", 100 * (double)region/(m*n));
putchar('\n');
}
return 0;
}