From 5f2a005ffd5052902a0c62c1c4c8f90eb1011fc3 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sat, 21 Jan 2017 11:22:06 +0700 Subject: Add others/153x/030.py --- others/153x/005.c | 46 +++++++++++++++++++++++++++++++ others/153x/006.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ others/153x/030.py | 19 +++++++++++++ others/153x/circle.c | 76 --------------------------------------------------- others/153x/fibistr.c | 46 ------------------------------- 5 files changed, 141 insertions(+), 122 deletions(-) create mode 100644 others/153x/005.c create mode 100644 others/153x/006.c create mode 100755 others/153x/030.py delete mode 100644 others/153x/circle.c delete mode 100644 others/153x/fibistr.c (limited to 'others') diff --git a/others/153x/005.c b/others/153x/005.c new file mode 100644 index 0000000..e3e55d8 --- /dev/null +++ b/others/153x/005.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; +} diff --git a/others/153x/006.c b/others/153x/006.c new file mode 100644 index 0000000..4d8947f --- /dev/null +++ b/others/153x/006.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/030.py b/others/153x/030.py new file mode 100755 index 0000000..f08d0d0 --- /dev/null +++ b/others/153x/030.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +with open("CUT.INP") as f: + m, n = map(int, f.readline().split()) + +squares = [] +while m - n: + if m > n: + m -= n + squares.append("{} 1 {}\n".format(m + 1, n)) + else: + n -= m + squares.append("1 {} {}\n".format(n + 1, m)) +squares.append("1 1 {}\n".format(m)) + +with open("CUT.OUT", "w") as f: + f.write("{}\n".format(len(squares))) + for i in squares: + f.write(i) diff --git a/others/153x/circle.c b/others/153x/circle.c deleted file mode 100644 index 4d8947f..0000000 --- a/others/153x/circle.c +++ /dev/null @@ -1,76 +0,0 @@ -#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 deleted file mode 100644 index e3e55d8..0000000 --- a/others/153x/fibistr.c +++ /dev/null @@ -1,46 +0,0 @@ -#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