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
|
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main (int argc, char ** argv) {
char * buf = malloc(6969);
fgets(buf, 6969, stdin);
char * c;
int N = strtol(buf, &c, 10); /* stevilo vrstic */
c++;
int M = strtol(c, NULL, 10); /** stevilo stolpcev */
c++;
int K = strtol(c, NULL, 10);
char ** m = malloc(N);
for (int i = 0; i < N; i++) {
m[i] = malloc(M);
fgets(m[i], M, stdin);
assert(!feof(stdin));
}
while (K) {
/* najdi prostor za postaviti. maksimalno 4 polja lahko naredimo, ko postavimo. */
int maksi = -1;
int maksj = -1;
int faktor = 0; /* prostih okoli */
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) {
/* zapolnimo take, ki imajo najmanj dva in največ osem prostih okoli sebe, čim manj */
if (m[i][j] != '.')
continue;
char u[9];
u[8] = 0;
if (i) {
u[0] = j ? m[i-1][j-1] : 'x';
u[1] = m[i-1][j];
u[2] = j < M-1 ? m[i-1][j+1] : 'x';
} else {
u[0] = 'x';
u[1] = 'x';
u[2] = 'x';
}
u[3] = j < M-1 ? m[i][j+1] : 'x';
if (i < N-1) {
u[4] = j < M-1 ? m[i+1][j+1] : 'x';
u[5] = m[i+1][j];
u[6] = j ? m[i+1][j-1] : 'x';
} else {
u[4] = 'x';
u[5] = 'x';
u[6] = 'x';
}
u[7] = j ? m[i][j-1] : 'x';
while (strchr(u, 'o'))
*strchr(u) = 'x';
int stanje = 0;
int povr = 0;
for (int o = 0; o < 8; o++) {
if (stanje != u[o] && u[o] == '.' && o % 2)
povr++;
stanje = u[o];
}
}
}
}
|