about summary refs log tree commit diff
path: root/codechef
diff options
context:
space:
mode:
Diffstat (limited to 'codechef')
-rw-r--r--codechef/bitobyt.lisp10
-rw-r--r--codechef/chefprms.c37
-rwxr-xr-xcodechef/chefprms.py21
-rw-r--r--codechef/chserve.c15
-rw-r--r--codechef/qabc.c39
-rw-r--r--codechef/qabc.lisp18
-rwxr-xr-xcodechef/qabc.py20
-rw-r--r--codechef/qualprel.c26
-rwxr-xr-xcodechef/qualprel.py9
-rw-r--r--codechef/spread2.lisp14
-rw-r--r--codechef/teammate.py14
11 files changed, 223 insertions, 0 deletions
diff --git a/codechef/bitobyt.lisp b/codechef/bitobyt.lisp
new file mode 100644
index 0000000..6a26b93
--- /dev/null
+++ b/codechef/bitobyt.lisp
@@ -0,0 +1,10 @@
+(let ((tests (read)))
+  (dotimes (i tests)
+    (let ((n (read)))
+      (if (= n 0)
+          (format t "1 0 0~&")
+          (multiple-value-bind (d m) (truncate (1- n) 26)
+            (format t (cond ((< m 2) "~a 0 0~&")
+                            ((< m 10) "0 ~a 0~&")
+                            (t "0 0 ~a~&"))
+                    (expt 2 d)))))))
diff --git a/codechef/chefprms.c b/codechef/chefprms.c
new file mode 100644
index 0000000..1e80bda
--- /dev/null
+++ b/codechef/chefprms.c
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+const int chefprms[] = {
+	12, 16, 20, 21, 24, 25, 27, 28, 29, 30, 31, 32, 35, 36, 37, 39, 40, 41,
+	42, 43, 44, 45, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 59, 60, 61, 63,
+	64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
+	83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
+	101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
+	115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128,
+	129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
+	143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
+	157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,
+	171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
+	185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
+	199, 200};
+
+int cmp(const void *x, const void *y)
+{
+	return *(int *) x - *(int *) y;
+}
+
+int main()
+{
+	int t, n;
+	scanf("%d\n", &t);
+
+	while (t--) {
+		scanf("%d\n", &n);
+		if (bsearch(&n, chefprms, 172, sizeof(int), cmp) == NULL)
+			puts("NO");
+		else
+			puts("YES");
+	}
+
+	return 0;
+}
diff --git a/codechef/chefprms.py b/codechef/chefprms.py
new file mode 100755
index 0000000..355606b
--- /dev/null
+++ b/codechef/chefprms.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+from itertools import combinations, combinations_with_replacement
+from operator import add, mul
+
+
+def prime(n):
+    """Check if n is a prime using trial division."""
+    for i in range(2, n):
+        if not n%i: return False
+    return True
+
+
+def up200(n): return n <= 200
+def apply(f): return lambda x: f(*x)
+
+
+primes = filter(prime, range(2, 200))
+semis = set(filter(up200, map(apply(mul), combinations(primes, 2))))
+chefprms = filter(up200, map(apply(add),
+                             combinations_with_replacement(semis, 2)))
+print(len(set(chefprms)))
diff --git a/codechef/chserve.c b/codechef/chserve.c
new file mode 100644
index 0000000..1ad088c
--- /dev/null
+++ b/codechef/chserve.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main()
+{
+	int t;
+	long p, q, k;
+
+	scanf("%d\n", &t);
+	while (t--) {
+		scanf("%ld %ld %ld\n", &p, &q, &k);
+		puts(((p + q) / k % 2) ? "COOK" : "CHEF");
+	}
+
+	return 0;
+}
diff --git a/codechef/qabc.c b/codechef/qabc.c
new file mode 100644
index 0000000..0dd8b5a
--- /dev/null
+++ b/codechef/qabc.c
@@ -0,0 +1,39 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+int main()
+{
+	int t, n, i;
+	long *a = malloc(10000 * sizeof(long)), b;
+	scanf("%d\n", &t);
+
+	while (t--) {
+		scanf("%d\n", &n);
+		for (i = 0; i < n; i++)
+			scanf("%ld", a + i);
+		for (i = 0; i < n; i++) {
+			scanf("%ld", &b);
+			a[i] = b - a[i];
+		}
+
+		for (n--; --n; a++) {
+			if (*a < 0) {
+				puts("NIE");
+				break;
+			}
+			if (*a) {
+				a[1] -= *a * 2;
+				a[2] -= *a * 3;
+			}
+		}
+
+		if (n)
+			continue;
+		if (*a || *++a)
+			puts("NIE");
+		else
+			puts("TAK");
+	}
+
+	return 0;
+}
diff --git a/codechef/qabc.lisp b/codechef/qabc.lisp
new file mode 100644
index 0000000..7c9619b
--- /dev/null
+++ b/codechef/qabc.lisp
@@ -0,0 +1,18 @@
+(defun read-list (str)
+  (read-from-string (concatenate 'string "(" str ")")))
+
+(defun qabc (seq n &optional (a1 0) (a2 0))
+  (if (< n 3)
+      (if (every #'zerop (mapcar #'- (list a1 a2) seq)) "TAK" "NIE")
+      (let ((a0 (- (first seq) a1)))
+        (if (< a0 0)
+            "NIE"
+            (qabc (rest seq) (1- n) (+ a2 (* a0 2)) (* a0 3))))))
+
+(let ((tests (read)))
+  (dotimes (i tests)
+    (let* ((n (read))
+           (a (read-list (read-line)))
+           (b (read-list (read-line))))
+      (princ (qabc (mapcar #'- b a) n))
+      (fresh-line))))
diff --git a/codechef/qabc.py b/codechef/qabc.py
new file mode 100755
index 0000000..f3f9c60
--- /dev/null
+++ b/codechef/qabc.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python2
+from operator import not_, sub
+from sys import stdin
+
+for _ in xrange(int(stdin.readline())):
+    n = int(stdin.readline())
+    a = map(int, stdin.readline().split())
+    b = map(int, stdin.readline().split())
+    c = map(sub, b, a)
+    for i in xrange(n - 2):
+        if c[i] < 0:
+            print 'NIE'
+            break
+        c[i + 1] -= c[i] * 2
+        c[i + 2] -= c[i] * 3
+    else:
+        if n < 3:
+            print 'NIE' if any(c) else 'TAK'
+        else:
+            print 'TAK' if c[-2] == c[-1] == 0 else 'NIE'
diff --git a/codechef/qualprel.c b/codechef/qualprel.c
new file mode 100644
index 0000000..a920592
--- /dev/null
+++ b/codechef/qualprel.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+int cmp(const void *x, const void *y)
+{
+	long tmp = *(long *) y - *(long *) x;
+	return tmp ? tmp / labs(tmp) : tmp;
+}
+
+int main()
+{
+	int t, k, n, i;
+	long *s = malloc(10000 * sizeof(long));
+	scanf("%d\n", &t);
+
+	while (t--) {
+		scanf("%d %d\n", &n, &k);
+		for (i = 0; i < n; i++)
+			scanf("%ld", s + i);
+		qsort(s, n, sizeof(long), cmp);
+		for (i = k; i < n && s[k - 1] == s[i]; i++);
+		printf("%d\n", i);
+	}
+
+	return 0;
+}
diff --git a/codechef/qualprel.py b/codechef/qualprel.py
new file mode 100755
index 0000000..400974c
--- /dev/null
+++ b/codechef/qualprel.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python2
+from bisect import bisect_right
+from sys import stdin
+
+for _ in xrange(int(stdin.readline())):
+    n, k = map(int, stdin.readline().split())
+    s = [1000000000 - int(i) for i in stdin.readline().split()]
+    s.sort()
+    print bisect_right(s, s[k - 1])
diff --git a/codechef/spread2.lisp b/codechef/spread2.lisp
new file mode 100644
index 0000000..db26024
--- /dev/null
+++ b/codechef/spread2.lisp
@@ -0,0 +1,14 @@
+(defun next (m result)
+  (if (> m 0)
+      (next (1- m) (+ (read) result))
+      result))
+
+(defun spread2 (n sum &optional (result 1))
+  (if (< sum n)
+      (spread2 (- n sum) (next sum sum) (1+ result))
+      (dotimes (i n result) (read))))
+
+(let ((tests (read)))
+  (dotimes (i tests)
+    (format t "~a~&" (spread2 (1- (read)) (read)))))
+
diff --git a/codechef/teammate.py b/codechef/teammate.py
new file mode 100644
index 0000000..cc3846e
--- /dev/null
+++ b/codechef/teammate.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+from collections import defaultdict
+
+for _ in range(int(input())):
+    n = int(input())
+    s = map(int, input().split())
+    d = defaultdict(int)
+    for i in s: d[i] += 1
+    result = 0
+    for value in s.values():
+        if value % 2:
+            pass
+        else:
+            result += value * (value-1) // 2