summaryrefslogtreecommitdiffstats
path: root/inf/zotksd/2.c
diff options
context:
space:
mode:
Diffstat (limited to 'inf/zotksd/2.c')
-rw-r--r--inf/zotksd/2.c88
1 files changed, 88 insertions, 0 deletions
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");
+}