1
0
Fork 0

So I gave up on a number theory one

This commit is contained in:
Nguyễn Gia Phong 2019-07-15 19:58:48 +07:00
parent 6c0ea3cc33
commit be6678fbca
4 changed files with 97 additions and 0 deletions

12
codechef/chfm.py Executable file
View File

@ -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')

32
codechef/cirmerge.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
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;
}

6
codechef/mmax.py Executable file
View File

@ -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))

47
codechef/prtagn.c Normal file
View File

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
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;
}