summaryrefslogtreecommitdiffstats
path: root/inf/zotksd
diff options
context:
space:
mode:
Diffstat (limited to 'inf/zotksd')
-rwxr-xr-xinf/zotksd/1bin0 -> 282656 bytes
-rw-r--r--inf/zotksd/1.c57
-rw-r--r--inf/zotksd/1.txt8
-rw-r--r--inf/zotksd/1.txt28
-rwxr-xr-xinf/zotksd/2bin0 -> 284000 bytes
-rw-r--r--inf/zotksd/2.c88
-rw-r--r--inf/zotksd/2.txt3
-rw-r--r--inf/zotksd/2.txt24
-rwxr-xr-xinf/zotksd/3bin0 -> 282408 bytes
-rw-r--r--inf/zotksd/3.c22
-rwxr-xr-xinf/zotksd/4bin0 -> 283072 bytes
-rw-r--r--inf/zotksd/4.c96
-rw-r--r--inf/zotksd/4.txt2
-rw-r--r--inf/zotksd/4.txt22
14 files changed, 290 insertions, 0 deletions
diff --git a/inf/zotksd/1 b/inf/zotksd/1
new file mode 100755
index 0000000..a11970d
--- /dev/null
+++ b/inf/zotksd/1
Binary files differ
diff --git a/inf/zotksd/1.c b/inf/zotksd/1.c
new file mode 100644
index 0000000..7a2de18
--- /dev/null
+++ b/inf/zotksd/1.c
@@ -0,0 +1,57 @@
+// naloge ne razumem najbolje
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#define S 25000
+int main (void) {
+ int crke[25];
+ char buf[S];
+ fgets(buf, S, stdin);
+ int n = strtol(buf, NULL, 10);
+ for (int i = 0; i < n; i++) {
+ int crkecopy[25];
+ memcpy(crkecopy, crke, sizeof(crke));
+ fgets(buf, S, stdin);
+ char dodaten = -1;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-compare"
+ if (strlen(buf) != i+1 && 0) {
+#ifndef EVAL
+ fprintf(stderr, "napačna dolžina niza %s na indeksu %d\n", buf, i);
+#endif
+ printf("%d\n", i);
+ return 0;
+ }
+#pragma GCC diagnostic pop
+#ifndef EVAL
+ fprintf(stderr, "pri i==%d obdelujem niz %s", i, buf);
+#endif
+ for (int j = 0; j <= i; j++) {
+ int crka = buf[j]-'A';
+ if (--crkecopy[crka] < 0) {
+ if (dodaten != -1) {
+ printf("%d\n", i);
+#ifndef EVAL
+ fprintf(stderr, "konec, ker je preveč novih, dodaten je %c\n", dodaten+'A');
+#endif
+ return 0;
+ }
+ dodaten = crka;
+#ifndef EVAL
+ fprintf(stderr, "i==%d, dodaten je sedaj %c\n", i, dodaten+'A');
+#endif
+ crke[crka]++;
+ }
+ }
+ for (int j = 0; j < 25; j++)
+ if (crkecopy[j] != 0 && crkecopy[j] != -1) {
+ printf("%d\n", i);
+#ifndef EVAL
+ fprintf(stderr, "konec, ker ni pobrisal vseh\n");
+#endif
+ return 0;
+ }
+ }
+ printf("%d\n", n);
+ return 0;
+}
diff --git a/inf/zotksd/1.txt b/inf/zotksd/1.txt
new file mode 100644
index 0000000..9820f10
--- /dev/null
+++ b/inf/zotksd/1.txt
@@ -0,0 +1,8 @@
+7
+R
+AR
+RAK
+TRAK
+KARTA
+RAKETA
+TRAKTOR
diff --git a/inf/zotksd/1.txt2 b/inf/zotksd/1.txt2
new file mode 100644
index 0000000..334d077
--- /dev/null
+++ b/inf/zotksd/1.txt2
@@ -0,0 +1,8 @@
+7
+R
+AR
+RAK
+TRAK
+KARTA
+RAKETAx
+TRAKTOR
diff --git a/inf/zotksd/2 b/inf/zotksd/2
new file mode 100755
index 0000000..d5071c2
--- /dev/null
+++ b/inf/zotksd/2
Binary files differ
diff --git a/inf/zotksd/2.c b/inf/zotksd/2.c
new file mode 100644
index 0000000..4b6be92
--- /dev/null
+++ b/inf/zotksd/2.c
@@ -0,0 +1,88 @@
+// todo: moje karte so drevo
+#include <stdlib.h>
+#include <stdio.h>
+#ifdef EVAL
+#define NDEBUG 1
+#endif
+#include <assert.h>
+#define SI 10000000
+static int compar (const void * a, const void * b) {
+ return *(int *) a < *(int *) b;
+}
+int in_arr (int elem, int * ar /* najv do najm */, int len) {
+ int prej = -1; // zadnja obstoječa karta
+ for (int i = 0; i < len; i++) {
+ if (ar[i] == -1) // prazen element -- vzeta karta
+ continue;
+ if (elem == ar[i])
+ return -1; // moja karta
+ if (elem > ar[i]) {
+ if (prej == -1)
+ return -2; // njegova karta, izguba
+ return prej;
+ }
+ prej = i;
+ }
+#ifndef EVAL
+ fprintf(stderr, "najmanjša karta idx %d vrednost %d\n", len-1, ar[len-1]);
+#endif
+ return len-1;
+}
+int main (void) {
+ char * buf = malloc(SI);
+ fgets(buf, SI, stdin);
+ char * cp = buf;
+ int igralcev = strtol(cp, &cp, 10);
+ int kart = strtol(++cp, NULL, 10);
+ int NK = igralcev*kart;
+ int * moje = malloc(sizeof*moje*kart);
+ int ** njihove = malloc(sizeof*njihove*igralcev);
+ fgets(buf, SI, stdin);
+ cp = buf;
+ for (int j = 0; j < kart; j++) {
+ moje[j] = strtol(cp, &cp, 10);
+ cp++;
+ }
+ qsort(moje, kart, sizeof(int), compar);
+ for (int i = 0; i < igralcev-1; i++) {
+ njihove[i] = malloc(sizeof*moje*kart);
+ fgets(buf, SI, stdin);
+ cp = buf;
+ for (int j = 0; j < kart; j++) {
+ njihove[i][j] = strtol(cp, &cp, 10);
+ cp++;
+ }
+ qsort(njihove[i], kart, sizeof(int), compar);
+ }
+#ifndef EVAL
+ for (int i = 0; i < kart; i++)
+ fprintf(stderr, "%d ", moje[i]);
+ fprintf(stderr, "\n%d %d\n", in_arr(6, moje, kart), in_arr(3, moje, kart));
+ for (int i = 0; i < igralcev-1; i++) {
+ fprintf(stderr, "igralec %d: ", i);
+ for (int j = 0; j < kart; j++)
+ fprintf(stderr, "%d ", njihove[i][j]);
+ fprintf(stderr, "\n");
+ }
+#endif
+ for (int stih = 0; stih < kart; stih++) {
+ int najv = 0;
+ for (int i = 0; i < igralcev-1; i++)
+ if (najv < njihove[i][stih])
+ najv = njihove[i][stih];
+#ifndef EVAL
+ fprintf(stderr, "štih z najv karto %d ", najv);
+#endif
+ int ret = in_arr(najv, moje, kart);
+ assert(ret != -1); // ne more biti moja karta
+ if (ret == -2) {
+ puts("NE\n"); // on ima večjo karto
+ return 0;
+ }
+#ifndef EVAL
+ fprintf(stderr, "premagam in porabim karto %d na idx %d\n", moje[ret], ret);
+#endif
+ moje[ret] = -1; // porabim karto
+ }
+ puts("DA\n");
+}
diff --git a/inf/zotksd/2.txt b/inf/zotksd/2.txt
new file mode 100644
index 0000000..68d7fe9
--- /dev/null
+++ b/inf/zotksd/2.txt
@@ -0,0 +1,3 @@
+2 3
+4 2 6
+5 1 3
diff --git a/inf/zotksd/2.txt2 b/inf/zotksd/2.txt2
new file mode 100644
index 0000000..77472da
--- /dev/null
+++ b/inf/zotksd/2.txt2
@@ -0,0 +1,4 @@
+3 4
+7 10 6 12
+8 11 4 9
+1 3 5 2
diff --git a/inf/zotksd/3 b/inf/zotksd/3
new file mode 100755
index 0000000..ffb3da7
--- /dev/null
+++ b/inf/zotksd/3
Binary files differ
diff --git a/inf/zotksd/3.c b/inf/zotksd/3.c
new file mode 100644
index 0000000..b7723b1
--- /dev/null
+++ b/inf/zotksd/3.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#define ABS(x) ((x) > 0 ? (x) : -(x))
+#define N unsigned long long int
+int main (void) {
+ char buf[512];
+ fgets(buf, 512, stdin);
+ N n = strtoull(buf, NULL, 10);
+ N num = 0;
+ for (N i = 1; i < ceill(sqrtl(n)); i++) {
+ if (n % i)
+ continue;
+ if (ABS(i-n/i) % 2)
+ continue;
+ num++;
+#ifndef EVAL
+ fprintf(stderr, "(%llu, %llu)\n", i, n/i);
+#endif
+ }
+ printf("%llu\n", num);
+}
diff --git a/inf/zotksd/4 b/inf/zotksd/4
new file mode 100755
index 0000000..634ce55
--- /dev/null
+++ b/inf/zotksd/4
Binary files differ
diff --git a/inf/zotksd/4.c b/inf/zotksd/4.c
new file mode 100644
index 0000000..4c3113a
--- /dev/null
+++ b/inf/zotksd/4.c
@@ -0,0 +1,96 @@
+// todo: pazi na težave s prvim elementom
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#define S 1600002
+#define ABS(x) ((x) > 0 ? (x) : -(x))
+int main (void) {
+ int ukazov = 0;
+ char buf[S];
+ fgets(buf, S, stdin);
+ int n = strtol(buf, NULL, 10);
+ fgets(buf, S, stdin);
+ char * cp = buf;
+ int * arr = calloc(n, sizeof *arr);
+ int * repr = calloc(10e6, sizeof *arr);
+ int najrepr = 0;
+ int najreprval = 0;
+ for (int i = 0; i < n; i++) {
+ arr[i] = strtol(cp, &cp, 10);
+ if (++repr[arr[i]] > najreprval) {
+ najreprval = repr[arr[i]];
+ najrepr = arr[i];
+ }
+ cp++;
+ }
+ free(repr);
+ int razd_od_centr = INT_MAX;
+ int center = 0;
+ if (najreprval == 1) {
+ najrepr = arr[n/2];
+ center = n/2;
+ }
+ for (int i = 0; i < n; i++) {
+ if (arr[i] == najrepr && ABS(n/2-i) < razd_od_centr) {
+ razd_od_centr = ABS(n/2-i);
+ center = i;
+ }
+ }
+ if (najreprval == 1) {
+ center = n/2;
+ }
+#ifndef EVAL
+ fprintf(stderr, "najrepr je število %d, ki ima toliko pojavitev: %d\n", najrepr, najreprval);
+#endif
+ int levo = 0;
+ int desno = n-1;
+ s:
+ while (arr[levo] == najrepr) {
+ if (levo == n-1)
+ goto k;
+ levo++;
+ }
+ while (arr[desno] == najrepr) {
+ if (desno == 0)
+ goto k;
+ desno--;
+ }
+ if (levo == desno) {
+ ukazov++;
+ goto k;
+ }
+ if (center > levo && center < desno) {
+ ukazov++;
+ arr[levo] = najrepr;
+ arr[desno] = najrepr;
+#ifndef EVAL
+ fprintf(stderr, "(%d, %d, %d) .. cached center\n", levo, center, desno);
+#endif
+ goto s;
+ }
+ center = 0;
+ for (int i = levo+1; i < desno; i++) {
+ if (arr[i] == najrepr) {
+ center = i;
+ arr[levo] = najrepr;
+ arr[desno] = najrepr;
+ ukazov++;
+#ifndef EVAL
+ fprintf(stderr, "(%d, %d, %d) .. našel center, en ukaz\n", levo, center, desno);
+#endif
+ goto s;
+ }
+ }
+ if (center == 0) {
+ ukazov += 2;
+ arr[levo] = najrepr;
+ arr[desno] = najrepr;
+ arr[(center = levo+(desno-levo)/2)] = najrepr;
+#ifndef EVAL
+ fprintf(stderr, "(%d, %d, %d) .. ni bilo centra, dva ukaza\n", levo, center, desno);
+#endif
+ goto s;
+ }
+ k:
+ printf("%d\n", ukazov);
+}
diff --git a/inf/zotksd/4.txt b/inf/zotksd/4.txt
new file mode 100644
index 0000000..b10a269
--- /dev/null
+++ b/inf/zotksd/4.txt
@@ -0,0 +1,2 @@
+5
+1 3 2 3 4
diff --git a/inf/zotksd/4.txt2 b/inf/zotksd/4.txt2
new file mode 100644
index 0000000..7191255
--- /dev/null
+++ b/inf/zotksd/4.txt2
@@ -0,0 +1,2 @@
+11
+2 2 2 1 1 1 1 1 2 2 2