summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inf/liga/.gitignore4
-rw-r--r--inf/liga/1.1.txt5
-rw-r--r--inf/liga/1.2.txt4
-rw-r--r--inf/liga/1.3.txt8
-rw-r--r--inf/liga/1.c49
-rw-r--r--inf/liga/2.1.txt1
-rw-r--r--inf/liga/2.c118
-rw-r--r--inf/liga/3.c19
-rw-r--r--inf/liga/Makefile15
-rw-r--r--inf/liga/test.c5
10 files changed, 228 insertions, 0 deletions
diff --git a/inf/liga/.gitignore b/inf/liga/.gitignore
new file mode 100644
index 0000000..94ebaf9
--- /dev/null
+++ b/inf/liga/.gitignore
@@ -0,0 +1,4 @@
+1
+2
+3
+4
diff --git a/inf/liga/1.1.txt b/inf/liga/1.1.txt
new file mode 100644
index 0000000..87f4c7a
--- /dev/null
+++ b/inf/liga/1.1.txt
@@ -0,0 +1,5 @@
+10 30
+1
+-1
+-1
+0
diff --git a/inf/liga/1.2.txt b/inf/liga/1.2.txt
new file mode 100644
index 0000000..944b5a9
--- /dev/null
+++ b/inf/liga/1.2.txt
@@ -0,0 +1,4 @@
+10 30
+1
+-1
+0
diff --git a/inf/liga/1.3.txt b/inf/liga/1.3.txt
new file mode 100644
index 0000000..fb8c257
--- /dev/null
+++ b/inf/liga/1.3.txt
@@ -0,0 +1,8 @@
+10 30
+-1
+-1
+-1
+1
+1
+-1
+0
diff --git a/inf/liga/1.c b/inf/liga/1.c
new file mode 100644
index 0000000..955cd89
--- /dev/null
+++ b/inf/liga/1.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#define M 512
+#define pedantic_fgets(a, b, c) if (!fgets(a, b, c)) { fprintf(stderr, "napaka pri vnosu\n"); return 1; }
+int main (void) {
+ char buf[M];
+ char * c;
+ int a, b, s;
+ pedantic_fgets(buf, M, stdin);
+ a = strtol(buf, &c, 10);
+ b = strtol(++c, NULL, 10);
+ if (a > b) {
+ s = a; /* swap */
+ a = b;
+ b = s;
+ }
+ fprintf(stderr, "interval: %05d %05d\n", a, b);
+ while (1) {
+ int v, u;
+ u = (a+b)/2; /* ugibamo to */
+ fprintf(stderr, "testiram %05d\n", u);
+ pedantic_fgets(buf, M, stdin);
+ if (!(v = strtol(buf, NULL, 10))) {
+ if ((b-a) <= 1)
+ goto ogabno;
+ fprintf(stdout, "%d %d\n", a, b);
+ return 0; /* da se CMS ne zmede */
+ }
+ if ((b-a) <= 1) { /* našli smo število */
+ogabno:
+ if (v)
+ fprintf(stdout, "PROTISLOVJE\n");
+ else
+ fprintf(stdout, "%d\n", u);
+ return 0;
+ }
+ if (v == -1) {
+ b = u;
+ b--;
+ fprintf(stderr, "-1: število je manjše od %05d, interval %05d %05d\n", u, a, b);
+ }
+ if (v == 1) {
+ a = u;
+ a++;
+ fprintf(stderr, " 1: število je večje od %05d, interval %05d %05d\n", u, a, b);
+ }
+ }
+ return 0;
+}
diff --git a/inf/liga/2.1.txt b/inf/liga/2.1.txt
new file mode 100644
index 0000000..ed40cec
--- /dev/null
+++ b/inf/liga/2.1.txt
@@ -0,0 +1 @@
+10 20
diff --git a/inf/liga/2.c b/inf/liga/2.c
new file mode 100644
index 0000000..25ccbe5
--- /dev/null
+++ b/inf/liga/2.c
@@ -0,0 +1,118 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <unistd.h>
+#include <string.h>
+#define M 512
+#define pedantic_fgets(a, b, c) if (!fgets(a, b, c)) { fprintf(stderr, "napaka pri vnosu\n"); return 1; }
+struct p {
+ long long int a;
+ long long int b;
+};
+int main (void) {
+ char buf[M];
+ char * cp;
+ long long int m, n, s, a, b, c;
+ m = n = s = a = b = c = 0; /* uh */
+ pedantic_fgets(buf, M, stdin);
+ m = strtoll(buf, &cp, 10);
+ if (!*++cp) return 1;
+ n = strtoll(cp, NULL, 10);
+ struct p * r = calloc(M, sizeof(struct p));
+ int u = 0;
+ fprintf(stderr, "interval je [%lld; %lld]\n", m, n);
+#if 0
+ for (a = 1; a <= n; a++)
+ for (b = 1; b <= n; b++)
+ for (c = 1; c <= n; c++) {
+ if (c >= m && c <= n && a*a+b*b == c*c) {
+ for (int i = 0; i < u; i++) {
+ if ((r[i].a == a && r[i].b == b)
+ || (r[i].a == b && r[i].b == a)) {
+#ifndef EVAL
+ fprintf(stderr, "ogabno\n");
+#endif
+ goto ogabno;
+ }
+ }
+ r[u].a = a;
+ r[u++].b = b;
+#ifndef EVAL
+ fprintf(stderr, "%lld² + %lld² = %lld²\n", a, b, c);
+#endif
+ s++;
+ogabno:;
+ }
+ }
+ fprintf(stdout, "%lld\n", s);
+#endif
+#if 0
+ for (int a = 1; a <= n; a++)
+ for (int b = a+1; b <= n; b++) { /* a < b, b < c <= pravzaprav to sploh ni res*/
+ for (c = b+1; c*c < a*a+b*b; c++); /* koren je počasnejši */
+ if (c >= m && c <= n && a*a + b*b == c*c)
+ s++;
+ }
+#endif
+#if 0 /* eulerjeva metoda ne generira vseh trojic */
+ /* a = x² - y²
+ b = 2xy
+ c = x²+y² */
+#define COND (c < 100)
+ for (int x = 2; COND; x++) {
+ for (int y = 1; y < x; y++) {
+ c = x*x+y*y;
+#ifndef EVAL
+ a = x*x-y*y;
+ b = 2*x*y;
+ fprintf(stderr, "%d²+%d²=%d² ", a, b, c);
+#endif
+ if (c >= m && c <= n) {
+#ifndef EVAL
+ fprintf(stderr, "ŠTEJEMO\n");
+#endif
+ s++;
+ }
+#ifndef EVAL
+ else {
+ fprintf(stderr, "NE ŠTEJEMO\n");
+ }
+#endif
+ }
+ }
+#endif
+#if 0
+ for (a = 1; a <= n; a++)
+ for (b = 1; b <= n; b++) {
+ double e = a*a+b*b;
+ double d = sqrt(e);
+#ifndef EVAL /* CMS compila z -DEVAL */
+ fprintf(stderr, "preverjam (%lld^2 + %lld^2 = %lf) = %lf^2\n", a, b, e, d);
+#endif
+ if ((int) d >= m && (int) d <= n && d == (int) d) {
+ for (int i = 0; i < u; i++) {
+ if ((r[i].a == a && r[i].b == b)
+ || (r[i].a == b && r[i].b == a)) {
+#ifndef EVAL
+ fprintf(stderr, "ogabno\n");
+#endif
+ goto ogabno;
+ }
+ }
+ r[u].a = a;
+ r[u++].b = b;
+ s++;
+ogabno:;
+ }
+ }
+#endif
+ for (a = 1; a <= n; a++)
+ for (b = 1; b <= n; b++)
+ for (c = 1; c <= n; c++)
+ if (a*a+b*b=c*c) {
+
+ }
+ fprintf(stdout, "%lld\n", s);
+ return 0;
+}
diff --git a/inf/liga/3.c b/inf/liga/3.c
new file mode 100644
index 0000000..9d370e6
--- /dev/null
+++ b/inf/liga/3.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <stdlib.h>
+#define M 512
+#define pedantic_fgets(a, b, c) if (!fgets(a, b, c)) { fprintf(stderr, "napaka pri vnosu\n"); return 1; }
+int main (void) {
+ char buf[M];
+ char * c;
+ int n, k, r;
+ pedantic_fgets(buf, M, stdin);
+ n = strtol(buf, NULL, stdin);
+ pedantic_fgets(buf, M, stdin);
+ k = strtol(buf, NULL, stdin);
+ pedantic_fgets(buf, M, stdin);
+ r = strtol(buf, NULL, stdin);
+ while (fddgets(buf, M, stdin)) {
+
+ }
+ return 0;
+}
diff --git a/inf/liga/Makefile b/inf/liga/Makefile
new file mode 100644
index 0000000..1dd50ea
--- /dev/null
+++ b/inf/liga/Makefile
@@ -0,0 +1,15 @@
+CFLAGS += -Wextra -Wall -pedantic -g -O0 -finput-charset=UTF-8 -fanalyzer -fextended-identifiers
+LDFLAGS += -lm
+CC ?= cc
+SHELL ?= /bin/sh
+cbins := $(subst .c,,$(wildcard *.c))
+asmbins := $(subst .asm,,$(wildcard *.asm))
+default: $(cbins) $(asmbins)
+%: %.c
+ $(CC) $(CFLAGS) $< -o$@ $(LDFLAGS)
+%: %.asm
+ # za zdaj sicer še ni ničesar v zbornem jeziku, mogoče pa bo ...
+ nasm -f elf $< && ld -m elf_i386 -s -o $@ $@.o
+.PHONY: clean
+clean:
+ rm -f $(bins) $(asmbins) *.o
diff --git a/inf/liga/test.c b/inf/liga/test.c
new file mode 100644
index 0000000..b412386
--- /dev/null
+++ b/inf/liga/test.c
@@ -0,0 +1,5 @@
+int main (void) {
+ int a = 123;
+ double b = 123.4;
+ return (b == a);
+}