From 6750cd9d0a92f9f5ef544ea9f13ae3419769fb3b Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Fri, 20 Jan 2017 22:25:31 +0700 Subject: Add others/153x --- others/153x/README.md | 3 ++ others/153x/README.pdf | Bin 0 -> 1444073 bytes others/153x/circle.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ others/153x/fibistr.c | 46 ++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 others/153x/README.md create mode 100644 others/153x/README.pdf create mode 100644 others/153x/circle.c create mode 100644 others/153x/fibistr.c 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 Binary files /dev/null and b/others/153x/README.pdf differ diff --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 +#include +#include + +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 +#include +#include + +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; +} -- cgit 1.4.1