about summary refs log tree commit diff
path: root/codechef
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-05-14 11:55:28 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-05-14 11:55:28 +0700
commit267b2db7addc95c5eebb8bfb9ceeb7b953d85732 (patch)
tree8a9669a99fccaf520b3cb690143e539c58a92ca5 /codechef
parent887c286cc8228e13f85b587ab92b37e920161eb9 (diff)
downloadcp-267b2db7addc95c5eebb8bfb9ceeb7b953d85732.tar.gz
I has always believed that I'm good at solving math problems
Turns out I has been wrong all the time. And I'm not alone.
Diffstat (limited to 'codechef')
-rw-r--r--codechef/matchs.c23
-rw-r--r--codechef/matchs.scm13
-rw-r--r--codechef/redone.c19
-rw-r--r--codechef/wtbtr.c43
4 files changed, 98 insertions, 0 deletions
diff --git a/codechef/matchs.c b/codechef/matchs.c
new file mode 100644
index 0000000..7831378
--- /dev/null
+++ b/codechef/matchs.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#define MAX(x, y) (((n) > (m)) ? (n) : (m))
+#define MIN(x, y) (((n) > (m)) ? (m) : (n))
+
+int match(long long x, long long y, int ari)
+{
+	long long mod = x % y;
+	return (mod && x - y == mod) ? match(y, mod, !ari) : ari;
+}
+
+int main()
+{
+	int t;
+	long long n, m;
+
+	scanf("%d", &t);
+	while (t--) {
+		scanf("%lld %lld", &n, &m);
+		puts(match(MAX(n, m), MIN(n, m), 1) ? "Ari" : "Rich");
+	}
+
+	return 0;
+}
diff --git a/codechef/matchs.scm b/codechef/matchs.scm
new file mode 100644
index 0000000..2897b6d
--- /dev/null
+++ b/codechef/matchs.scm
@@ -0,0 +1,13 @@
+(define (match big smol ari)
+  (let ((mod (modulo big smol)))
+    (if (or (= mod 0) (> (quotient big smol) 1))
+        ari
+        (match smol mod (not ari)))))
+
+(let loop ((i (read)))
+  (when (> i 0)
+    (let ((n (read)) (m (read)))
+        (display (if (match (max n m) (min n m) #t)
+                     "Ari\n"
+                     "Rich\n")))
+    (loop (1- i))))
diff --git a/codechef/redone.c b/codechef/redone.c
new file mode 100644
index 0000000..b73fe0e
--- /dev/null
+++ b/codechef/redone.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+	long long *result = malloc(sizeof(long) * 1000001);
+	result[0] = 1;
+	for (long i = 1; i < 1000002; ++i)
+		result[i] = result[i - 1] * (i + 1) % 1000000007;
+	
+	long t, n;
+	scanf("%ld", &t);
+	while (t--) {
+		scanf("%ld", &n);
+		printf("%ld\n", (result[n] - 1) % 1000000007);
+	}
+	
+	return 0;
+}
diff --git a/codechef/wtbtr.c b/codechef/wtbtr.c
new file mode 100644
index 0000000..db8a90b
--- /dev/null
+++ b/codechef/wtbtr.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int cmpl(const void *x, const void *y)
+{
+	long tmp = *(long *) x - *(long *) y;
+	if (tmp > 0)
+		return 1;
+	if (tmp)
+		return -1;
+	return 0;
+}
+
+int main()
+{
+	int i, n, t;
+	long x, y, u[10000], v[10000];
+	scanf("%d", &t);
+
+	while (t--) {
+		scanf("%d", &n);
+		for (i = 0; i < n; ++i) {
+			scanf("%ld %ld", &x, &y);
+			u[i] = x + y;
+			v[i] = x - y;
+		}
+
+		qsort(u, n, sizeof(long), cmpl);
+		qsort(v, n, sizeof(long), cmpl);
+
+		long tmp, min = u[n - 1] - *u;
+		for (i = 1; i < n; ++i)
+			if ((tmp = u[i] - u[i - 1]) < min)
+				min = tmp;
+		for (i = 1; i < n; ++i)
+			if ((tmp = v[i] - v[i - 1]) < min)
+				min = tmp;
+
+		printf("%.1f\n", min / 2.0);
+	}
+
+	return 0;
+}