diff options
author | sijanec <anton@sijanec.eu> | 2021-05-31 00:06:03 +0200 |
---|---|---|
committer | sijanec <anton@sijanec.eu> | 2021-05-31 00:06:03 +0200 |
commit | 62233e62e73210d07b2daf86ce04f80278f8a2ee (patch) | |
tree | 7856caa8fdbda910a52871428a06ca19d2232fd3 /inf/ioi/4/prog.c | |
parent | ang test (diff) | |
download | sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.tar sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.tar.gz sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.tar.bz2 sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.tar.lz sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.tar.xz sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.tar.zst sola-gimb-2-62233e62e73210d07b2daf86ce04f80278f8a2ee.zip |
Diffstat (limited to '')
-rw-r--r-- | inf/ioi/4/prog.c | 62 |
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]; + } + } + } +} |