summaryrefslogtreecommitdiffstats
path: root/inf/rtk/2021-izbirno
diff options
context:
space:
mode:
Diffstat (limited to 'inf/rtk/2021-izbirno')
-rwxr-xr-xinf/rtk/2021-izbirno/1/a.outbin0 -> 20296 bytes
-rw-r--r--inf/rtk/2021-izbirno/1/prog.c62
-rwxr-xr-xinf/rtk/2021-izbirno/2/a.outbin0 -> 20696 bytes
-rw-r--r--inf/rtk/2021-izbirno/2/in.txt2
-rw-r--r--inf/rtk/2021-izbirno/2/prog.c64
-rwxr-xr-xinf/rtk/2021-izbirno/3/a.outbin0 -> 17200 bytes
-rw-r--r--inf/rtk/2021-izbirno/3/in.txt7
-rw-r--r--inf/rtk/2021-izbirno/3/prog.c86
-rw-r--r--inf/rtk/2021-izbirno/p/p.c5
9 files changed, 226 insertions, 0 deletions
diff --git a/inf/rtk/2021-izbirno/1/a.out b/inf/rtk/2021-izbirno/1/a.out
new file mode 100755
index 0000000..354664c
--- /dev/null
+++ b/inf/rtk/2021-izbirno/1/a.out
Binary files differ
diff --git a/inf/rtk/2021-izbirno/1/prog.c b/inf/rtk/2021-izbirno/1/prog.c
new file mode 100644
index 0000000..aa3e62d
--- /dev/null
+++ b/inf/rtk/2021-izbirno/1/prog.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (int argc, char ** argv) {
+ char * buf = malloc(500);
+ fgets(buf, 500, stdin);
+ char * cp;
+ int n = strtoll(buf, &cp, 10);
+ cp++;
+ int k = strtoll(cp, NULL, 10);
+ int * a = calloc(n+1, sizeof(int));
+ int * t = calloc(n+1, sizeof(int)); /* t[x] = ekipa št <od 1 do k> */
+ realloc(buf, (n+1)*6);
+ fgets(buf, (n+1)*6, stdin);
+ cp = buf;
+ int i = 0; /* i bo število zadnjega in hkrati število vseh, kajti prvi je 1 */
+ do {
+ int ai = strtoll(cp, &cp, 10);
+ if (ai != 0)
+ a[++i] = ai;
+ cp++;
+ } while (cp[-1] != 0 && cp[-1] != '\n' && cp[-1] != '\r');
+ if (i != n)
+ fprintf(stderr, "error %d ni %d\n", n, i);
+ int ze = 0; /* referencaj novo ekipo po (++ze % k)+1 */
+k1:
+ for (int j = 1; j <= n; j++) {
+ if (!t[(i = j)])
+ goto k2;
+ }
+ goto konec;
+k2:
+ /*
+ e = 0;
+ while (!t[zn]) {
+ if (!e++)
+ fprintf(stdout, "%d ", zn);
+ if (t[a[zn]]) { // če je naš a že v ekipi, i damo v to ekipo
+ t[zn] = t[a[zn]];
+ zn++;
+ }
+ t[zn] = (ze % k)+1;
+ zn = a[zn];
+ }
+ ze++;
+ */
+ if (ze)
+ fprintf(stdout, " ");
+ fprintf(stdout, "%d", i);
+ t[i] = ++ze;
+k3:
+ if (t[a[i]])
+ goto k1;
+k4:
+ i = a[i];
+k5:
+ t[i] = ze;
+ goto k3;
+konec:
+ fprintf(stdout, "\n");
+ free(buf);
+ return 0;
+}
diff --git a/inf/rtk/2021-izbirno/2/a.out b/inf/rtk/2021-izbirno/2/a.out
new file mode 100755
index 0000000..d23cc33
--- /dev/null
+++ b/inf/rtk/2021-izbirno/2/a.out
Binary files differ
diff --git a/inf/rtk/2021-izbirno/2/in.txt b/inf/rtk/2021-izbirno/2/in.txt
new file mode 100644
index 0000000..666efb4
--- /dev/null
+++ b/inf/rtk/2021-izbirno/2/in.txt
@@ -0,0 +1,2 @@
+10 1
+6 0 91 14 73 91 67 63 9 69
diff --git a/inf/rtk/2021-izbirno/2/prog.c b/inf/rtk/2021-izbirno/2/prog.c
new file mode 100644
index 0000000..eda85e9
--- /dev/null
+++ b/inf/rtk/2021-izbirno/2/prog.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <limits.h>
+int primerjaj_cela (const void * a, const void * b) {
+ const int * c = (const int *) a;
+ const int * d = (const int *) b;
+ return *d - *c; /* najv proti najm */
+}
+int main (int argc, char ** argv) {
+ char * buf = malloc(500);
+ fgets(buf, 500, stdin);
+ char * cp;
+ int N = strtoll(buf, &cp, 10);
+ cp++;
+ int M = strtoll(cp, NULL, 10);
+ int * x = calloc(N+1, sizeof(int));
+ int * g = malloc((M+1)*sizeof(int));
+ int * gl = malloc((M+1)*sizeof(int));
+ for (int o = 0; o < M; o++)
+ g[o] = INT_MAX;
+ realloc(buf, (N+1)*6*9);
+ fgets(buf, (N+1)*6*9, stdin);
+ cp = buf;
+ int i = 0;
+ int mx = 0;
+ do {
+ int xi = strtoll(cp, &cp, 10);
+ // if (xi != 0)
+ x[++i] = xi;
+ if (xi > mx)
+ mx = xi;
+ cp++;
+ } while (cp[-1] != 0 && cp[-1] != '\n' && cp[-1] != '\r');
+ free(buf);
+ if (N != i) {
+ fprintf(stderr, "error %d ni %d\n", N, i);
+ for (int o = 1; o <= i; o++)
+ fprintf(stderr, " %d\n", x[o]);
+ }
+ fprintf(stderr, "max = %d\n", mx);
+ for (i = 0; i <= mx; i++) {
+ int s = 0;
+ for (int j = 1; j <= N; j++)
+ s += abs(i-x[j]);
+ int mo = 0;
+ int me = 0;
+ for (int o = 0; o < M; o++) {
+ if (g[o] > mo) {
+ mo = g[o];
+ me = o;
+ }
+ }
+ if (mo > s)
+ g[me] = s;
+ }
+ int s = 0;
+ for (int o = 0; o < M; o++) {
+ fprintf(stderr, "GOSTILNA %d ima seštevek %d\n", o, g[o]);
+ s += g[o];
+ }
+ fprintf(stdout, "%d\n", s);
+ return 0;
+}
diff --git a/inf/rtk/2021-izbirno/3/a.out b/inf/rtk/2021-izbirno/3/a.out
new file mode 100755
index 0000000..d7053de
--- /dev/null
+++ b/inf/rtk/2021-izbirno/3/a.out
Binary files differ
diff --git a/inf/rtk/2021-izbirno/3/in.txt b/inf/rtk/2021-izbirno/3/in.txt
new file mode 100644
index 0000000..d8d19ab
--- /dev/null
+++ b/inf/rtk/2021-izbirno/3/in.txt
@@ -0,0 +1,7 @@
+5 4
+1 1 3 3
+5 4 1 2 1
+1 1 8
+2 1 10
+1 1 8
+1 3 0
diff --git a/inf/rtk/2021-izbirno/3/prog.c b/inf/rtk/2021-izbirno/3/prog.c
new file mode 100644
index 0000000..0686c60
--- /dev/null
+++ b/inf/rtk/2021-izbirno/3/prog.c
@@ -0,0 +1,86 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <limits.h>
+int main (int argc, char ** argv) {
+ char * buf = (char *) malloc(500);
+ fgets(buf, 500, stdin);
+ char * cp;
+ int n = strtoll(buf, &cp, 10);
+ cp++;
+ int q = strtoll(cp, NULL, 10);
+ int * r = (int *) calloc(n+1, sizeof(int));
+ int * x = (int *) calloc(n+1, sizeof(int));
+ realloc(buf, (n+1)*6*9);
+ fgets(buf, (n+1)*6*9, stdin);
+ cp = buf;
+ int i = 1; /* začnemo z delavcem 2, ker 1 nima starša */
+ do {
+ int xi = strtoll(cp, &cp, 10);
+ if (xi != 0)
+ r[++i] = xi;
+ cp++;
+ } while (cp[-1] != 0 && cp[-1] != '\n' && cp[-1] != '\r');
+ i = 0; /* začnemo z delavcem 1 */
+ fgets(buf, (n+1)*6*9, stdin);
+ cp = buf;
+ do {
+ int xi = strtoll(cp, &cp, 10);
+ if (xi != 0)
+ x[++i] = xi;
+ cp++;
+ } while (cp[-1] != 0 && cp[-1] != '\n' && cp[-1] != '\r');
+ if (n != i)
+ fprintf(stderr, "error %d ni %d\n", n, i);
+ else
+ fprintf(stderr, "st\n");
+ fgets(buf, 1000, stdin);
+ while (!feof(stdin)) {
+ cp = buf;
+ if (cp[0] == '1') { /* GET */
+ cp += 2;
+ int d = strtol(cp, &cp, 10);
+ cp++;
+ int t = strtol(cp, NULL, 10);
+ int o = INT_MAX;
+ for (int i = 1; i <= n; i++) {
+ int p = i;
+ int y = 0;
+ while (1) {
+ if (p == d) {
+ y++;
+ break;
+ }
+ if (p == 1)
+ break;
+ p = r[p];
+ }
+ if (!y)
+ continue;
+ else
+ fprintf(stderr, "GET V HIER: %d\n", i);
+ if (x[i] > t && x[i] < o) {
+ fprintf(stderr, " x[i] == %d\n", x[i]);
+ o = x[i];
+ }
+ }
+ if (o == INT_MAX)
+ o = -1;
+ fprintf(stdout, "%d\n", o);
+ } else { /* POST */
+ cp += 2;
+ int d = strtol(cp, &cp, 10);
+ cp++;
+ int t = strtol(cp, NULL, 10);
+ x[d] = t;
+ fprintf(stderr, "POST OK: { ");
+ for (int i = 1; i <= n; i++) {
+ fprintf(stderr, "%d:%d, ", i, x[i]);
+ }
+ fprintf(stderr, "}\n");
+ }
+ fgets(buf, 1000, stdin);
+ }
+ free(buf);
+ return 0;
+}
diff --git a/inf/rtk/2021-izbirno/p/p.c b/inf/rtk/2021-izbirno/p/p.c
new file mode 100644
index 0000000..7f02924
--- /dev/null
+++ b/inf/rtk/2021-izbirno/p/p.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+#include <stdlib.h>
+int main (int argc, char ** argv) {
+ return 0;
+}