From be6678fbca007e73d69c9a9c5cddb8241a987149 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 15 Jul 2019 19:58:48 +0700 Subject: So I gave up on a number theory one --- codechef/chfm.py | 12 ++++++++++++ codechef/cirmerge.c | 32 ++++++++++++++++++++++++++++++++ codechef/mmax.py | 6 ++++++ codechef/prtagn.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100755 codechef/chfm.py create mode 100644 codechef/cirmerge.c create mode 100755 codechef/mmax.py create mode 100644 codechef/prtagn.c diff --git a/codechef/chfm.py b/codechef/chfm.py new file mode 100755 index 0000000..99b3d99 --- /dev/null +++ b/codechef/chfm.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +for _ in range(int(input())): + input() + a = [int(i) for i in input().split()] + d, m = divmod(sum(a), len(a)) + if m: + print('Impossible') + continue + try: + print(a.index(d) + 1) + except ValueError: + print('Impossible') diff --git a/codechef/cirmerge.c b/codechef/cirmerge.c new file mode 100644 index 0000000..678f47a --- /dev/null +++ b/codechef/cirmerge.c @@ -0,0 +1,32 @@ +#include + +int main() +{ + int t, n, i, j, k; + long long tmp, a[400][400], p[400][400] = {}; + + for (scanf("%d", &t); t--; printf("%lld\n", tmp)) { + scanf("%d", &n); + for (i = 0; i < n; ++i) + scanf("%lld", *a + i); + + for (i = 1; i < n; ++i) + for (j = 0; j < n; ++j) { + p[i][j] = p[i-1][j]; + for (k = 1; k < i; ++k) { + tmp = p[k-1][j] + p[i-k][(j+k)%n]; + if (tmp < p[i][j]) + p[i][j] = tmp; + } + p[i][j] += a[i][j] = a[i-1][j] + a[0][(i+j)%n]; + } + + long long *m = p[n-1]; + tmp = *m; + for (i = 1; i < n; ++i) + if (m[i] < tmp) + tmp = m[i]; + } + + return 0; +} diff --git a/codechef/mmax.py b/codechef/mmax.py new file mode 100755 index 0000000..e62fc7d --- /dev/null +++ b/codechef/mmax.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +for _ in range(int(input())): + n = int(input()) + k = int(input()) + m = k % n + print(min(m * 2, (n - m) * 2, n - 1)) diff --git a/codechef/prtagn.c b/codechef/prtagn.c new file mode 100644 index 0000000..deadb6f --- /dev/null +++ b/codechef/prtagn.c @@ -0,0 +1,47 @@ +#include +#include + +int prt(long n) +{ + int tmp; + for (tmp = n & 1; n >>= 1; tmp ^= n & 1); + return tmp; +} + +int main() +{ + char t; + long q, x, z, *s = malloc(sizeof(long) << 17); + + scanf("%hhd", &t); + while (t--) { + char *in = calloc(1 << 17, sizeof(char)); + long e = 0, o = 0, *p = s; + + scanf("%ld", &q); + while (q--) { + scanf("%ld", &x); + if (in[x]) { + printf("%ld %ld\n", e, o); + continue; + } + + long *y = p; + while (y-- > s) + if ((z = x ^ *y) && !in[z]) { + *p++ = z; + in[z] = 1; + prt(z) ? o++ : e++; + } + + *p++ = x; + in[x] = 1; + prt(x) ? o++ : e++; + printf("%ld %ld\n", e, o); + } + + free(in); + } + + return 0; +} -- cgit 1.4.1