about summary refs log tree commit diff
path: root/others
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-20 22:25:31 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-20 22:31:32 +0700
commit6750cd9d0a92f9f5ef544ea9f13ae3419769fb3b (patch)
treeb3d2c74093c2b7be5f019179b9c295c97da5d9eb /others
parent1fca99158c60a94497b21ff527d4071d96c9c0f1 (diff)
downloadcp-6750cd9d0a92f9f5ef544ea9f13ae3419769fb3b.tar.gz
Add others/153x
Diffstat (limited to 'others')
-rw-r--r--others/153x/README.md3
-rw-r--r--others/153x/README.pdfbin0 -> 1444073 bytes
-rw-r--r--others/153x/circle.c76
-rw-r--r--others/153x/fibistr.c46
4 files changed, 125 insertions, 0 deletions
diff --git a/others/153x/README.md b/others/153x/README.md
new file mode 100644
index 0000000..fbcbf1e
--- /dev/null
+++ b/others/153x/README.md
@@ -0,0 +1,3 @@
+# [150+ Bài toán tin](https://github.com/McSinyx/hsg/raw/master/others/153x/README.pdf) - Lê Minh Hoàng
+
+Đại học Sư phạm Hà Nội 2004 - 2006
diff --git a/others/153x/README.pdf b/others/153x/README.pdf
new file mode 100644
index 0000000..c1125f1
--- /dev/null
+++ b/others/153x/README.pdf
Binary files differdiff --git a/others/153x/circle.c b/others/153x/circle.c
new file mode 100644
index 0000000..4d8947f
--- /dev/null
+++ b/others/153x/circle.c
@@ -0,0 +1,76 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char N, P[10] = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31}, **A, *B, *D, *E;
+long C = 0;
+
+int cmp(const void *x, const void *y)
+{
+	return (int) (*(char *) x - *(char *) y);
+}
+
+void circle(FILE *f, char idx)
+{
+	char i, tmp;
+
+	if (idx == N * 2) {
+		tmp = *D + D[idx - 1];
+		if (bsearch(&tmp, P, 10, 1, cmp) != NULL) {
+			C++;
+			E = realloc(E, C * N * 2);
+			memcpy(E + (C - 1) * N * 2, D, N * 2);
+		}
+		return;
+	}
+
+	for (i = 1; i < *A[D[idx - 1] - 1]; i++) {
+		tmp = A[D[idx - 1] - 1][i];
+		if (B[tmp - 1]) {
+			B[tmp - 1] = 0;
+			D[idx] = tmp;
+			circle(f, idx + 1);
+			B[tmp - 1] = 1;
+		}
+	}
+}
+
+int main()
+{
+	FILE *f = fopen("CIRCLE.INP", "r");
+	long i;
+	char j;
+
+	fscanf(f, "%hhd", &N);
+	fclose(f);
+
+	A = malloc(N * 2 * sizeof(char *));
+	for (i = 0; i < N * 2; i++) {
+		A[i] = malloc(sizeof(char));
+		*A[i] = 1;
+		for (j = 0; j < 10; j++)
+			if (i + 1 < P[j] && P[j] < N * 2 + i + 2) {
+				A[i] = realloc(A[i], ++*A[i]);
+				A[i][*A[i] - 1] = P[j] - i - 1;
+			}
+	}
+
+	B = calloc(N * 2, sizeof(char));
+	for (i = 1; i < N * 2; i++)
+		B[i] = 1;
+	D = malloc(N * 2);
+	D[0] = 1;
+	E = malloc(1);
+	circle(f, 1);
+
+	f = fopen("CIRCLE.OUT", "w");
+	fprintf(f, "%ld\n", C);
+	for (i = 0; i < C * N * 2; i++) {
+		for (; i % (N * 2) < N * 2 - 1; i++)
+			fprintf(f, "%hhd ", E[i]);
+		fprintf(f, "%hhd\n", E[i]);
+	}
+	fclose(f);
+
+	return 0;
+}
diff --git a/others/153x/fibistr.c b/others/153x/fibistr.c
new file mode 100644
index 0000000..e3e55d8
--- /dev/null
+++ b/others/153x/fibistr.c
@@ -0,0 +1,46 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char streq(char *x, char *y)
+{
+	char i;
+
+	for (i = 0; i < strlen(x); i++)
+		if (x[i] != y[i])
+			return 0;
+
+	return 1;
+}
+
+int main()
+{
+	FILE *fi = fopen("FIBISTR.INP", "r"), *fo = fopen("FIBISTR.OUT", "w");
+	char **fibi = malloc(35 * sizeof(char *)), s[26], n;
+	long i, c;
+
+	fibi[0] = malloc(2);
+	fibi[1] = malloc(2);
+	fibi[0][0] = 65;
+	fibi[1][0] = 66;
+	fibi[0][1] = fibi[1][1] = 0;
+
+	for (i = 2; i < 35; i++) {
+		fibi[i] = malloc(strlen(fibi[i - 1]) + strlen(fibi[i - 2]) + 1);
+		strcpy(fibi[i], fibi[i - 1]);
+		strcpy(fibi[i] + strlen(fibi[i - 1]), fibi[i - 2]);
+	}
+
+	do {
+		fscanf(fi, "%hhd %s\n", &n, s);
+		n--;
+		c = 0;
+		for (i = strlen(fibi[n]) - strlen(s); i >= 0; i--)
+			c += streq(s, fibi[n] + i);
+		fprintf(fo, "%ld\n", c);
+	} while (!feof(fi));
+
+	fcloseall();
+	return 0;
+}