1
0
Fork 0

At least I managed to stay in top 10%

This commit is contained in:
Nguyễn Gia Phong 2019-01-14 20:41:09 +07:00
parent bf53895481
commit ce56bd193a
7 changed files with 89 additions and 0 deletions

17
codechef/dpairs.py Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
from bisect import bisect_left as bsearch
input()
X, A = zip(*sorted(enumerate(map(int, input().split())), key=lambda t: t[1]))
Y, B = zip(*sorted(enumerate(map(int, input().split())), key=lambda t: t[1]))
N, M = len(A), len(B)
i = j = 0
for _ in range(N + M - 1):
print(X[i], Y[j])
try:
if A[i + 1] < B[j + 1]: i += 1
else: j += 1
except IndexError:
if i + 1 < N: i += 1
else: j += 1

23
codechef/eartseq.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
from math import gcd
from itertools import cycle, islice
from sys import stdin
CANDIDATES = cycle(range(2, 30000))
a, b, new = 30011, 30013, {}
coprimes, result = [a, b], [a * b]
for _ in range(49998):
for i in CANDIDATES:
if new.get(b * i, True) and gcd(a, i) == 1 == gcd(b, i):
coprimes.append(i)
a, b = b, i
break
new[a * b] = False
result.append(a * b)
next(stdin)
for N in map(int, stdin):
N -= 1
print(coprimes[N] * 30011, end=' ')
print(*islice(result, N))

2
codechef/fancy.p6 Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env perl6
for ^get() { put /<<not>>/ ?? 'Real Fancy' !! 'regularly fancy' for get }

10
codechef/hp18.py Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env python3
from functools import reduce
from math import gcd
for t in range(int(input())):
N, a, b = map(int, input().split())
lcm = a * b // gcd(a, b)
rm = map(lambda x: (x%a==0, x%lcm==0, x%b==0), map(int, input().split()))
Bob, both, Alice = reduce(lambda x, y: map(int.__add__, x, y), rm)
print('BOB' if Bob + bool(both) > Alice else 'ALICE')

23
codechef/mgame.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#define sqr(x) ((x) * (x))
int main() {
long long t, n, p, diff, u, v;
scanf("%lld", &t);
while(t--) {
scanf("%lld %lld", &n, &p);
if (n < 3) {
printf("%lld\n", p * p * p);
continue;
}
diff = p - n;
if (diff % 2) {
u = n / 2, v = diff/2;
printf("%lld\n", (u+v*3+2)*(u+v*3+3) + v*(v+1)*3 + 1);
} else {
printf("%lld\n", sqr(p/2 + diff + 1) + sqr(diff)*3/4);
}
}
return 0;
}

8
codechef/xypizq.lisp Normal file
View File

@ -0,0 +1,8 @@
(defun xypizq (N q x y z)
(cond ((= q 1) (if (= x z) (/ x (1+ (* N 2))) (- 1 (xypizq N 1 z y z))))
((= q 3) (xypizq N 1 z y x))
(t (- 1 (/ (* y 2) (1+ (* N 2)))))))
(dotimes (tests (read))
(let ((result (xypizq (read) (read) (read) (read) (read))))
(format t "~a ~a~&" (numerator result) (denominator result))))

6
codechef/xypizq.p6 Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env perl6
multi xypizq($N, 1, $x, $y, $z where $x == $z) { $x / ($N * 2 + 1) }
multi xypizq($N, 1, $x, $y, $z) { 1 - xypizq $N, 1, $z, $y, $z }
multi xypizq($N, 3, $x, $y, $z) { xypizq $N, 1, $z, $y, $x }
multi xypizq($N, $t, $x, $y, $z) { 1 - $y * 2 / ($N * 2 + 1) }
xypizq(|get.words>>.Int).nude.put for ^get