summaryrefslogtreecommitdiffstats
path: root/inf/ioi/4/prog.c
diff options
context:
space:
mode:
Diffstat (limited to 'inf/ioi/4/prog.c')
-rw-r--r--inf/ioi/4/prog.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/inf/ioi/4/prog.c b/inf/ioi/4/prog.c
new file mode 100644
index 0000000..d36bfcd
--- /dev/null
+++ b/inf/ioi/4/prog.c
@@ -0,0 +1,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];
+ }
+ }
+ }
+}