about summary refs log tree commit diff
path: root/THT
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-31 22:21:50 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-10-31 22:21:50 +0700
commit71a6e456b59171a681bccff7eeba9db7367bca37 (patch)
treee6f517c4b4109e13c9bb31df6c4c40185ad7ddf7 /THT
parent250b7d75204bb18311f51d8b67164f9ad4cef9f2 (diff)
downloadcp-71a6e456b59171a681bccff7eeba9db7367bca37.tar.gz
Thêm đề Tin học trẻ Quốc gia 2016 Bảng B
Diffstat (limited to 'THT')
-rw-r--r--THT/B/QG-2016/QG-2016.pdfbin0 -> 690202 bytes
-rw-r--r--THT/B/QG-2016/TRIGRID.TXT15
-rw-r--r--THT/B/QG-2016/remainder.py19
-rwxr-xr-xTHT/B/QG-2016/trigrid.py10
-rw-r--r--THT/C/Q-2016/bai2.inp1
-rw-r--r--THT/C/Q-2016/bai2.out4
-rwxr-xr-xTHT/C/Q-2016/bai2.py47
-rwxr-xr-xTHT/C/Q-2016/bai3.py14
-rw-r--r--THT/C/TP-2016/buy.pas47
-rw-r--r--THT/C/TP-2016/play.pas77
-rw-r--r--THT/C/TP-2016/set.pas24
11 files changed, 258 insertions, 0 deletions
diff --git a/THT/B/QG-2016/QG-2016.pdf b/THT/B/QG-2016/QG-2016.pdf
new file mode 100644
index 0000000..e98feac
--- /dev/null
+++ b/THT/B/QG-2016/QG-2016.pdf
Binary files differdiff --git a/THT/B/QG-2016/TRIGRID.TXT b/THT/B/QG-2016/TRIGRID.TXT
new file mode 100644
index 0000000..c44f939
--- /dev/null
+++ b/THT/B/QG-2016/TRIGRID.TXT
@@ -0,0 +1,15 @@
+27
+13
+48
+78
+868
+168
+400
+1233
+685
+819
+1693
+342
+1504
+1252
+576
diff --git a/THT/B/QG-2016/remainder.py b/THT/B/QG-2016/remainder.py
new file mode 100644
index 0000000..45681ca
--- /dev/null
+++ b/THT/B/QG-2016/remainder.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+
+l = [
+        (12, 3, 8),
+        (2, 15, 17),
+        (456, 6, 1296),
+        (1234, 100, 9),
+        (11223344, 1000000, 142857),
+        (55667788, 10000000, 1000000007),
+        (1357, 24682468, 999999999),
+        (24680, 1357913579, 777777777),
+        (998, 1000000000000, 999),
+        (1234, 11111111111111, 30),
+        (1, 222222222222222, 123456789),
+        (2016, 666666666666666, 8888888888),
+        (11223344, 555666777888999, 1357924680),
+        (999999999999999967, 999999999999999877, 999999999999999989),
+        (123456789123456789, 123456789123456789, 987654321123456789)
+]
diff --git a/THT/B/QG-2016/trigrid.py b/THT/B/QG-2016/trigrid.py
new file mode 100755
index 0000000..ea33d07
--- /dev/null
+++ b/THT/B/QG-2016/trigrid.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+
+a = (4, 3, 5, 6, 111, 222, 3333, 4444, 55555, 666666, 7777777, 88888888,
+     999999999, 123456789123456789, 1000000000000000000)
+
+t = lambda n: n * (n + 2) * (n * 2 + 1) // 8 % 2016
+
+with open('TRIGRID.TXT', 'w') as f:
+    for i in a:
+        f.write("{}\n".format(t(i)))
diff --git a/THT/C/Q-2016/bai2.inp b/THT/C/Q-2016/bai2.inp
new file mode 100644
index 0000000..9a73285
--- /dev/null
+++ b/THT/C/Q-2016/bai2.inp
@@ -0,0 +1 @@
+1-2.(3-4.5)
diff --git a/THT/C/Q-2016/bai2.out b/THT/C/Q-2016/bai2.out
new file mode 100644
index 0000000..b0a3d7f
--- /dev/null
+++ b/THT/C/Q-2016/bai2.out
@@ -0,0 +1,4 @@
+1-2.(3-4.5)
+=1-2.(3-4.5)
+=1-2.(3-20)
+=1-2.-17
diff --git a/THT/C/Q-2016/bai2.py b/THT/C/Q-2016/bai2.py
new file mode 100755
index 0000000..bb04c54
--- /dev/null
+++ b/THT/C/Q-2016/bai2.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+d = {'+': '+', '-': '-', '.': '*', ':': '/', '^': '**'}
+
+def Steps(string):
+    val = int()
+    for char in string:
+        if char in '+-.:^':
+            val += 1
+    return val
+
+def Calc(string):
+    global d
+    for char in '+-.:^':
+        string = string.replace(char, ' {} '.format(char))
+    l = string.split()
+    for char in '^.:+-':
+        if char in l:
+            idx = l.index(char)
+            s = ' '.join(l[idx - 1:idx + 2])
+            return string.replace(s, str(eval(s.replace(char, d[char]))))
+
+def MetaCalc(string):
+    for idx0, char0 in enumerate(string):
+        if char0 == ')':
+            for idx1, char1 in enumerate(reversed(string)):
+                if char1 == '(':
+                    idx1 = len(string) - idx1 - 1
+                    s = '({})'.format(Calc(string[idx1 + 1:idx0]))
+                    if not(Steps(s)) or ((Steps(s) == 1) and (s[:2] == '(-')):
+                        s = s[1:-1]
+                    return string.replace(string[idx1:idx0 + 1], s)
+    return Calc(string)
+
+with open('bai2.inp') as f:
+    s = f.readline()
+lines = Steps(s)
+for i in d:
+    s = s.replace(i, ' ' + i + ' ')
+for i in d:
+    s = s.replace(i + ' - ', i + ' -')
+l = s.split()
+with open('bai2.out', 'w') as f:
+    f.write(''.join(l) + '\n')
+    for _ in range(lines):
+        s = MetaCalc(s).replace(' ', '')
+        f.write('=' + s)
+        print(s)
diff --git a/THT/C/Q-2016/bai3.py b/THT/C/Q-2016/bai3.py
new file mode 100755
index 0000000..f4139a9
--- /dev/null
+++ b/THT/C/Q-2016/bai3.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+d = dict()
+with open('bai3.inp') as f:
+    for i in f.readlines():
+        for j in '.,;!?':
+            i = i.replace(j, ' ')
+        for j in i.split():
+            d[j] = d.get(j, 0) + 1
+l = [(value, key) for (key, value) in d.items()]
+l.sort(reverse=True)
+with open('bai3.out', 'w') as f:
+    f.write(str(len(l)) + '\n')
+    for i, j in l:
+        f.write('{} {}\n'.format(i, j))
diff --git a/THT/C/TP-2016/buy.pas b/THT/C/TP-2016/buy.pas
new file mode 100644
index 0000000..acbd1d3
--- /dev/null
+++ b/THT/C/TP-2016/buy.pas
@@ -0,0 +1,47 @@
+(* File name are supposed to be in upper case, but lower case names look more *mordern*.
+ * `buy.pas' run first, read input from `buy.inp', write to `buy.out'
+ * `set.pas' run next, read from `set.inp', write to `set.out'
+ * `play.pas' run last, read from `map.inp', write to `decision.out'
+ * (LMAO dunno how to sort files in Gist)
+ *)
+
+var
+  f : text;
+  a : array[1..10] of qword;
+  idx : array[1..10] of shortint = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+  out : array[1..10] of shortint = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+  i, j, smalltmp : shortint;
+  bigtmp : qword;
+
+begin
+  assign(f, 'buy.inp');
+  reset(f);
+  for i := 1 to 10 do
+    read(f, a[i]);
+  close(f);
+  for i := 1 to 9 do
+    for j := i + 1 to 10 do
+      if a[i] > a[j] then {should use `>=' cuz the later tanks are usually better}
+        begin
+          smalltmp := idx[i];
+          idx[i] := idx[j];
+          idx[j] := smalltmp;
+          bigtmp := a[i];
+          a[i] := a[j];
+          a[j] := bigtmp
+        end;
+  bigtmp := 100;
+  for i := 1 to 8 do {capable of buying 10, but dat gon' make `set.pas' complicated}
+    if a[i] > bigtmp then
+      break
+    else
+      begin
+        dec(bigtmp, a[i]);
+        out[idx[i]] := 1
+      end;
+  assign(f, 'buy.out');
+  rewrite(f);
+  for i := 1 to 10 do
+    writeln(f, out[i]);
+  close(f)
+end.
\ No newline at end of file
diff --git a/THT/C/TP-2016/play.pas b/THT/C/TP-2016/play.pas
new file mode 100644
index 0000000..8ae0d7c
--- /dev/null
+++ b/THT/C/TP-2016/play.pas
@@ -0,0 +1,77 @@
+type
+  tank = record
+    a, b, c, x, y : shortint
+  end;
+  tanklist = array[1..10] of tank;
+  out = record
+    x, y, u, v : shortint
+  end;
+
+var
+  f : text;
+  m, n, id, i, j, p : shortint;
+  t1, t2, ttmp : tanklist;
+  o : out;
+
+function shootable(tank0, tank1 : tank) : boolean;
+  begin
+    exit(abs(tank0.x - tank1.x) + abs(tank0.y - tank1.y) <= tank0.c)
+  end;
+
+{This function should also care about the target's HP, but never mind LOL}
+function damage(tank0 : tank) : shortint;
+  var
+    tmp : shortint;
+  begin
+     tmp := tank0.a * tank0.b;
+     if tmp mod 10 = 0 then
+      exit(tmp div 10);
+     exit(tmp div 10 + 1)
+  end;
+
+begin
+  assign(f, 'map.inp');
+  reset(f);
+  readln(f, m, n, id);
+  for i := 1 to m do
+    readln(f, t1[i].a, t1[i].b, t1[i].c, t1[i].x, t1[i].y);
+  for i := 1 to n do
+    readln(f, t2[i].a, t2[i].b, t2[i].c, t2[i].x, t2[i].y);
+  close(f);
+  if id = 2 then
+    begin
+      ttmp := t1;
+      t1 := t2;
+      t2 := ttmp;
+      i := m;
+      m := n;
+      n := i
+    end;
+  p := 0;
+  o.x := 0;
+  for i := 1 to m do
+    for j := 1 to n do
+      if shootable(t1[i], t2[j]) and (damage(t1[i]) > p) then
+        begin
+          p := damage(t1[i]);
+          o.x := t1[i].x;
+          o.y := t1[i].y;
+          o.u := t2[j].x;
+          o.v := t2[j].y
+        end;
+  assign(f, 'decision.out');
+  rewrite(f);
+  if o.x > 0 then
+    writeln(f, '2 ', o.x, ' ', o.y, ' ', o.u, ' ', o.v)
+  else
+    begin
+      randomize;
+      i := random(m) + 1;
+      write(f, '2 ', t1[i].x, ' ', t1[i].y, ' ');
+      if id = 1 then
+        writeln(f, random(4) + 5, ' ', random(4) + 5)
+      else
+        writeln(f, random(4) + 1, ' ', random(4) + 1)
+    end;
+  close(f)
+end.
\ No newline at end of file
diff --git a/THT/C/TP-2016/set.pas b/THT/C/TP-2016/set.pas
new file mode 100644
index 0000000..c36dc23
--- /dev/null
+++ b/THT/C/TP-2016/set.pas
@@ -0,0 +1,24 @@
+var
+  f : text;
+  m, n, id : shortint;
+  {This, because random failed on Windows, may because of not having /dev/urandom}
+  out : array[1..8] of shortint = (5, 1, 3, 7, 2, 6, 4, 8);
+
+begin
+  assign(f, 'set.inp');
+  reset(f);
+  readln(f, m, n, id);
+  close(f);
+  if id = 2 then
+    begin
+      m := n;
+      n := 5
+    end
+  else
+    n := 4;
+  assign(f, 'set.out');
+  rewrite(f);
+  for id := 1 to m do
+    writeln(f, n, ' ', out[id]);
+  close(f)
+end.
\ No newline at end of file