summaryrefslogtreecommitdiffstats
path: root/inf/zotksd/2
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
4 files changed, 95 insertions, 0 deletions
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