forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10873.cpp
90 lines (86 loc) · 1.39 KB
/
10873.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
int loc[64], w, h;
void push(int c)
{
loc[c]++;
if (loc[c - 1] <= (loc[c] - 3) && loc[c + 1] <= (loc[c] - 3))
{
loc[c] -= 2;
push(c - 1);
push(c + 1);
}
else if (loc[c - 1] <= (loc[c] - 3))
{
loc[c]--;
push(c - 1);
}
else if (loc[c + 1] <= (loc[c] - 3))
{
loc[c]--;
push(c + 1);
}
}
int main()
{
static struct
{
int s, r, c, n, z;
} feed[3];
int i, j, t = 1;
while (scanf("%d %d", &w, &h) == 2 && w > 0)
{
memset(feed, 0, sizeof(feed));
for (i = 0; i < 3; i++)
{
scanf("%d", &feed[i].s);
feed[i].z = (feed[i].s < 1);
}
for (i = 0; i < 3; i++)
{
scanf("%d", &feed[i].c);
feed[i].c++;
feed[i].r = 0;
}
memset(loc, 0, sizeof(loc));
loc[0] = loc[w + 1] = 0x3FFFFFFF;
for (;;)
{
for (i = 0; i < 3 && feed[i].z; i++)
;
if (i >= 3)
{
break;
}
for (j = feed[i++].r; i < 3; i++)
if (!feed[i].z && feed[i].r < j)
{
j = feed[i].r;
}
for (i = 0; i < 3; i++)
{
if (feed[i].z)
{
continue;
}
feed[i].r -= j;
if (feed[i].r > 0)
{
continue;
}
feed[i].r = feed[i].s;
if (loc[feed[i].c] >= h)
{
feed[i].z = 1;
continue;
}
feed[i].n++;
push(feed[i].c);
}
}
printf("Case %d: %d %d %d %d\n",
t++, feed[0].n, feed[1].n, feed[2].n,
w * h - feed[0].n - feed[1].n - feed[2].n);
}
return 0;
}