about summary refs log tree commit diff
path: root/THT/B
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-06-13 15:18:37 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-06-13 15:18:37 +0700
commit2b6ce5b49dedf4c6e6f41bd23a94f2f6a76d0a50 (patch)
tree1561fb72488a3dba1bab5549320e54d08170f37b /THT/B
parent69a50f40bea8f04c2d2b1715dad5ea8c7d6ef507 (diff)
downloadcp-2b6ce5b49dedf4c6e6f41bd23a94f2f6a76d0a50.tar.gz
Add THT/B/QG-2014
Diffstat (limited to 'THT/B')
-rw-r--r--THT/B/QG-2014/GIAODIEM.TXT10
-rw-r--r--THT/B/QG-2014/XEPHINH1.TXT6
-rw-r--r--THT/B/QG-2014/XEPHINH2.TXT8
-rw-r--r--THT/B/QG-2014/XEPHINH3.TXT7
-rw-r--r--THT/B/QG-2014/XEPHINH4.TXT15
-rw-r--r--THT/B/QG-2014/XEPHINH5.TXT15
-rwxr-xr-xTHT/B/QG-2014/dic.dat7
-rwxr-xr-xTHT/B/QG-2014/dic.pp96
-rw-r--r--THT/B/QG-2014/giaodiem.c29
-rw-r--r--THT/B/QG-2014/guess.pas17
-rwxr-xr-xTHT/B/QG-2014/sample.pas21
-rw-r--r--THT/B/QG-2014/xephinh.pas270
-rw-r--r--THT/B/QG-2016/trigrid.c1
13 files changed, 501 insertions, 1 deletions
diff --git a/THT/B/QG-2014/GIAODIEM.TXT b/THT/B/QG-2014/GIAODIEM.TXT
new file mode 100644
index 0000000..ba0199e
--- /dev/null
+++ b/THT/B/QG-2014/GIAODIEM.TXT
@@ -0,0 +1,10 @@
+1
+35
+210
+330
+1744
+210
+358
+1001
+1312
+1007
diff --git a/THT/B/QG-2014/XEPHINH1.TXT b/THT/B/QG-2014/XEPHINH1.TXT
new file mode 100644
index 0000000..0b884be
--- /dev/null
+++ b/THT/B/QG-2014/XEPHINH1.TXT
@@ -0,0 +1,6 @@
+1 2 3 3 3
+1 2 4 4 4
+1 2 5 5 4
+6 7 7 5 8
+6 7 5 5 8
+6 7 7 8 8
diff --git a/THT/B/QG-2014/XEPHINH2.TXT b/THT/B/QG-2014/XEPHINH2.TXT
new file mode 100644
index 0000000..8dc8e6a
--- /dev/null
+++ b/THT/B/QG-2014/XEPHINH2.TXT
@@ -0,0 +1,8 @@
+1 2 3 4 5 6 7 8 9 9 10 10
+1 2 3 4 5 6 7 8 9 11 10 12
+1 2 3 4 5 6 7 8 9 11 10 12
+13 13 14 15 15 15 16 16 11 11 12 12
+13 17 14 14 14 15 16 18 19 19 19 20
+13 17 17 17 21 21 16 18 18 18 19 20
+22 23 23 23 21 24 25 25 25 26 20 20
+22 22 22 23 21 24 24 24 25 26 26 26
diff --git a/THT/B/QG-2014/XEPHINH3.TXT b/THT/B/QG-2014/XEPHINH3.TXT
new file mode 100644
index 0000000..bdf97ba
--- /dev/null
+++ b/THT/B/QG-2014/XEPHINH3.TXT
@@ -0,0 +1,7 @@
+1 2 3 4 5 6 7 8 9 10 11 11 11
+1 2 3 4 5 6 7 8 9 10 12 12 11
+1 2 3 4 5 6 7 8 9 10 12 13 13
+14 14 14 15 15 15 16 16 17 17 12 12 13
+14 18 18 18 19 20 20 16 17 21 21 21 13
+22 18 22 18 19 20 16 16 17 21 23 21 23
+22 22 22 19 19 20 20 24 24 24 23 23 23
diff --git a/THT/B/QG-2014/XEPHINH4.TXT b/THT/B/QG-2014/XEPHINH4.TXT
new file mode 100644
index 0000000..497341c
--- /dev/null
+++ b/THT/B/QG-2014/XEPHINH4.TXT
@@ -0,0 +1,15 @@
+1 2 3 4 5 5 6 6 6 7
+1 2 3 4 5 8 6 8 6 7
+1 2 3 4 5 8 8 8 7 7
+9 10 11 12 13 13 14 14 14 15
+9 10 11 12 13 16 14 16 14 15
+9 10 11 12 13 16 16 16 15 15
+17 18 19 20 21 21 22 22 22 23
+17 18 19 20 21 24 22 24 22 23
+17 18 19 20 21 24 24 24 23 23
+25 26 27 28 29 29 30 30 30 31
+25 26 27 28 29 32 30 32 30 31
+25 26 27 28 29 32 32 32 31 31
+33 34 35 36 37 37 38 38 38 39
+33 34 35 36 37 40 38 40 38 39
+33 34 35 36 37 40 40 40 39 39
diff --git a/THT/B/QG-2014/XEPHINH5.TXT b/THT/B/QG-2014/XEPHINH5.TXT
new file mode 100644
index 0000000..550e630
--- /dev/null
+++ b/THT/B/QG-2014/XEPHINH5.TXT
@@ -0,0 +1,15 @@
+1 1 2 2 3 3 21 21 22 22 23 23 41 41 42 42 43 43 61 61 62 62 63 63 81 81 82 82 83 83
+1 4 2 5 5 3 21 24 22 25 25 23 41 44 42 45 45 43 61 64 62 65 65 63 81 84 82 85 85 83
+1 4 2 2 5 3 21 24 22 22 25 23 41 44 42 42 45 43 61 64 62 62 65 63 81 84 82 82 85 83
+4 4 6 7 5 7 24 24 26 27 25 27 44 44 46 47 45 47 64 64 66 67 65 67 84 84 86 87 85 87
+8 8 6 7 7 7 28 28 26 27 27 27 48 48 46 47 47 47 68 68 66 67 67 67 88 88 86 87 87 87
+8 6 6 9 9 9 28 26 26 29 29 29 48 46 46 49 49 49 68 66 66 69 69 69 88 86 86 89 89 89
+8 8 10 10 10 9 28 28 30 30 30 29 48 48 50 50 50 49 68 68 70 70 70 69 88 88 90 90 90 89
+11 11 10 12 10 12 31 31 30 32 30 32 51 51 50 52 50 52 71 71 70 72 70 72 91 91 90 92 90 92
+11 13 13 12 12 12 31 33 33 32 32 32 51 53 53 52 52 52 71 73 73 72 72 72 91 93 93 92 92 92
+11 11 13 14 14 14 31 31 33 34 34 34 51 51 53 54 54 54 71 71 73 74 74 74 91 91 93 94 94 94
+15 15 13 16 16 14 35 35 33 36 36 34 55 55 53 56 56 54 75 75 73 76 76 74 95 95 93 96 96 94
+15 17 17 16 18 18 35 37 37 36 38 38 55 57 57 56 58 58 75 77 77 76 78 78 95 97 97 96 98 98
+15 15 17 16 16 18 35 35 37 36 36 38 55 55 57 56 56 58 75 75 77 76 76 78 95 95 97 96 96 98
+19 17 17 20 18 18 39 37 37 40 38 38 59 57 57 60 58 58 79 77 77 80 78 78 99 97 97 100 98 98
+19 19 19 20 20 20 39 39 39 40 40 40 59 59 59 60 60 60 79 79 79 80 80 80 99 99 99 100 100 100
diff --git a/THT/B/QG-2014/dic.dat b/THT/B/QG-2014/dic.dat
new file mode 100755
index 0000000..bc5caec
--- /dev/null
+++ b/THT/B/QG-2014/dic.dat
@@ -0,0 +1,7 @@
+cat
+can
+mic
+man
+tiger
+hello
+world
diff --git a/THT/B/QG-2014/dic.pp b/THT/B/QG-2014/dic.pp
new file mode 100755
index 0000000..76f2323
--- /dev/null
+++ b/THT/B/QG-2014/dic.pp
@@ -0,0 +1,96 @@
+unit dic;
+interface
+  function count_char(c: char): longint;
+  function get_char_at_pos(x: longint): char;
+  procedure answer(s: string);
+
+implementation
+var
+  secret_word: string;
+  words: array [1..1000000] of string;
+  total_cost, n: longint;
+
+procedure answer(s: string);
+begin
+  if s = secret_word then
+  begin
+    writeln('Chuc mung ban da tim ra dap an chinh xac la "', s, '"');
+    writeln('Chi phi ban da su dung la ', total_cost);
+  end
+  else
+  begin
+    writeln('Dap an ban dua ra la "', s, '"');
+    writeln('Dap an chinh xac la "', secret_word, '"');
+  end;
+  halt;
+end;
+
+procedure cost_limit_exceed;
+begin
+  writeln('Chi phi ban da su dung vuot qua chi phi toi da cho phep');
+  halt;
+end;
+
+function count_char(c: char): longint;
+var
+  i, res: longint;
+begin
+  total_cost := total_cost + 1;
+  if (total_cost > 1000) then
+    cost_limit_exceed;
+  res := 0;
+  for i := 1 to length(secret_word) do
+    if secret_word[i] = c then
+      inc(res);
+  exit(res);
+end;
+
+function get_char_at_pos(x: longint): char;
+begin
+  total_cost := total_cost + 10;
+  if (total_cost > 1000) then
+    cost_limit_exceed;
+  if (x < 1) or (x > length(secret_word)) then
+    exit('#');
+  exit(secret_word[x]);
+end;
+
+procedure check_secret_word;
+var
+  f: text;
+  i: longint;
+  ok: boolean;
+begin
+  assign(f, 'dic.dat');
+  reset(f);
+  while not seekeof(f) do
+  begin
+    inc(n);
+    readln(f, words[n]);
+  end;
+  close(f);
+  ok := false;
+  for i := 1 to n do
+    if words[i] = secret_word then ok := true;
+  if not ok then
+  begin
+    writeln('Du lieu duoc khoi tao khong chinh xac. Dap an can tim khong nam trong tu dien');
+    halt;
+  end;
+end;
+
+procedure init;
+begin
+  writeln;
+  writeln('     TU DIEN     ');
+  writeln('*****************');
+  writeln;
+
+  secret_word := 'cat';
+  total_cost := 0;
+  check_secret_word;
+end;
+
+initialization
+  init;
+end.
diff --git a/THT/B/QG-2014/giaodiem.c b/THT/B/QG-2014/giaodiem.c
new file mode 100644
index 0000000..78ca9b2
--- /dev/null
+++ b/THT/B/QG-2014/giaodiem.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+const long long TESTS[] = {4, 7, 10, 11, 7777, 8888888, 1234567890, 9999999999,
+                           12345678912345, 2014201420142014};
+
+int main()
+{
+	char i, j, k, divisor;
+	long long n, p;
+	FILE *f = fopen("GIAODIEM.TXT", "w");
+
+	for (i = 0; i < 10; i++) {
+		divisor = 24;
+		p = 1;
+		for (j = 0; j < 4; j++) {
+			n = TESTS[i] - j;
+			for (k = 2; k < 4; k++) {
+				while (!(n % k + divisor % k)) {
+					n /= k;
+					divisor /= k;
+				}
+			}
+			p *= n % 2014;
+		}
+		fprintf(f, "%d\n", p % 2014);
+	}
+	fclose(f);
+	return 0;
+}
diff --git a/THT/B/QG-2014/guess.pas b/THT/B/QG-2014/guess.pas
new file mode 100644
index 0000000..cc036f8
--- /dev/null
+++ b/THT/B/QG-2014/guess.pas
@@ -0,0 +1,17 @@
+uses dic;
+
+var
+  s: string = '';
+  i: byte;
+  c: char;
+
+begin
+  for i := 1 to 50 do
+    begin
+      c := get_char_at_pos(i);
+      if c = '#' then
+        answer(s)
+      else
+        s := s + c
+    end
+end.
diff --git a/THT/B/QG-2014/sample.pas b/THT/B/QG-2014/sample.pas
new file mode 100755
index 0000000..c8b5e17
--- /dev/null
+++ b/THT/B/QG-2014/sample.pas
@@ -0,0 +1,21 @@
+uses dic;
+
+var
+  answer1: char;
+  answer2, answer3, answer4: longint;
+
+begin
+  answer1 := get_char_at_pos(4);
+  writeln('Vi tri thu 4 cua xau can tim la: ', answer1);
+
+  answer2 := count_char('c');
+  writeln('So luong ki tu c trong tu can tim la: ', answer2);
+
+  answer3 := count_char('a');
+  writeln('So luong ki tu a trong tu can tim la: ', answer3);
+
+  answer4 := count_char('n');
+  writeln('So luong ki tu n trong tu can tim la: ', answer4);
+
+  answer('can');
+end.
diff --git a/THT/B/QG-2014/xephinh.pas b/THT/B/QG-2014/xephinh.pas
new file mode 100644
index 0000000..d428302
--- /dev/null
+++ b/THT/B/QG-2014/xephinh.pas
@@ -0,0 +1,270 @@
+uses math;
+
+type
+  gift_t = record
+    filename: string;
+    m, n, a, b, c: byte
+  end;
+  piece_t = array[1..3, 1..3] of boolean;
+  board_t = array[1..15, 1..30] of byte;
+
+const
+  gifts: array[1..5] of gift_t = (
+    (filename: 'XEPHINH1.TXT'; m: 6; n: 5; a: 4; b: 2; c: 2),
+    (filename: 'XEPHINH2.TXT'; m: 8; n: 12; a: 8; b: 18; c: 0),
+    (filename: 'XEPHINH3.TXT'; m: 7; n: 13; a: 12; b: 5; c: 7),
+    (filename: 'XEPHINH4.TXT'; m: 3; n: 10; a: 4; b: 2; c: 2),
+    (filename: 'XEPHINH5.TXT'; m: 15; n: 6; a: 0; b: 10; c: 10)
+  );
+  pieces: array[1..3] of piece_t = (
+    ((false, true, false), (false, true, false), (false, true, false)),
+    ((false, true, true), (false, true, false), (false, true, false)),
+    ((false, true, true), (false, true, false), (false, true, true))
+  );
+
+var
+  f: text;
+  i, m, n, a, b, c: byte;
+  init_board: board_t;
+  done: boolean;
+
+
+function divide(dividend, divisor: smallint): smallint;
+  begin
+    if dividend mod divisor = 0 then
+      exit(dividend div divisor);
+    divide := dividend div divisor + 1
+  end;
+
+
+function modulo(dividend, divisor: smallint): smallint;
+  begin
+    if dividend mod divisor = 0 then
+      exit(divisor);
+    modulo := dividend mod divisor
+  end;
+
+
+function rotate(
+  piece: piece_t;
+  quarter: byte
+): piece_t;
+
+  var
+    i, j: byte;
+
+  begin
+    if quarter = 0 then
+      exit(piece);
+    for i := 1 to 3 do
+      for j := 1 to 3 do
+        rotate[i][j] := piece[j][4 - i];
+    exit(rotate(rotate, pred(quarter)))
+  end;
+
+
+function flip(piece: piece_t): piece_t;
+  var
+    i, j: byte;
+
+  begin
+    for i := 1 to 3 do
+      for j := 1 to 3 do
+        flip[i][j] := piece[4 - i][j]
+  end;
+
+
+function putable(
+  board: board_t;
+  y, x: byte;
+  piece: piece_t
+): boolean;
+
+  var
+    yoff, xoff, i, j: byte;
+
+  begin
+    if not piece[1][1] then
+      if piece[1][2] then
+        begin
+          yoff := 1;
+          xoff := 2
+        end
+      else
+        begin
+          yoff := 2;
+          xoff := 1
+        end
+    else
+      begin
+        yoff := 1;
+        xoff := 1
+      end;
+
+    for i := 1 to 3 do
+      for j := 1 to 3 do
+        if not piece[i][j] then
+          continue
+        else if not inrange(y + i - yoff, 1, m) or
+                not inrange(x + j - xoff, 1, n) or
+                (board[y + i - yoff][x + j - xoff] > 0) then
+          exit(false);
+    putable := true
+  end;
+
+
+function put(
+  board: board_t;
+  y, x: byte;
+  piece: piece_t;
+  no: byte
+): board_t;
+
+  var
+    yoff, xoff, i, j: byte;
+
+  begin
+    if not piece[1][1] then
+      if piece[1][2] then
+        begin
+          yoff := 1;
+          xoff := 2
+        end
+      else
+        begin
+          yoff := 2;
+          xoff := 1
+        end
+    else
+      begin
+        yoff := 1;
+        xoff := 1
+      end;
+
+    for i := 1 to 3 do
+      for j := 1 to 3 do
+        if piece[i][j] then
+           board[y + i - yoff][x + j - xoff] := no;
+    exit(board)
+  end;
+
+
+procedure solve(
+  board: board_t;
+  position: smallint;
+  no: byte
+);
+
+  var
+    y, x: smallint;
+    i: byte;
+
+  begin
+    if done then
+      exit;
+    while (board[divide(position, n)][modulo(position, n)] > 0) and
+          (position <= m * n) do
+      inc(position);
+    if position > m * n then
+      begin
+        for y := 1 to m do
+          begin
+            for x := 1 to n - 1 do
+              write(f, board[y][x], ' ');
+            writeln(f, board[y][n])
+          end;
+        done := true;
+        exit
+      end;
+
+    y := divide(position, n);
+    x := modulo(position, n);
+    for i := 0 to 1 do
+      if (a > 0) and
+         putable(board, y, x, rotate(pieces[1], i)) then
+        begin
+          dec(a);
+          solve(put(board, y, x, rotate(pieces[1], i), no), position, no + 1);
+          inc(a)
+        end;
+    for i := 0 to 3 do
+      if (b > 0) and
+         putable(board, y, x, rotate(pieces[2], i)) then
+        begin
+          dec(b);
+          solve(put(board, y, x, rotate(pieces[2], i), no), position, no + 1);
+          inc(b)
+        end;
+    for i := 1 to 3 do
+      if (b > 0) and
+         putable(board, y, x, rotate(flip(pieces[2]), i)) then
+        begin
+          dec(b);
+          solve(put(board, y, x, rotate(flip(pieces[2]), i), no), position, no + 1);
+          inc(b)
+        end;
+    for i := 0 to 3 do
+      if (c > 0) and
+         putable(board, y, x, rotate(pieces[3], i)) then
+        begin
+          dec(c);
+          solve(put(board, y, x, rotate(pieces[3], i), no), position, no + 1);
+          inc(c)
+        end;
+  end;
+
+
+begin
+  for i := 1 to 5 do
+    begin
+      assign(f, gifts[i].filename);
+      rewrite(f);
+      m := gifts[i].m;
+      n := gifts[i].n;
+      for a := 1 to m do
+        for b := 1 to n do
+          init_board[a][b] := 0;
+      a := gifts[i].a;
+      b := gifts[i].b;
+      c := gifts[i].c;
+      done := false;
+      solve(init_board, 1, 1);
+      close(f)
+    end;
+
+  assign(f, 'XEPHINH4.TXT');
+  reset(f);
+  for m := 1 to 3 do
+    for n := 1 to 10 do
+      read(f, init_board[m][n]);
+  close(f);
+  assign(f, 'XEPHINH4.TXT');
+  rewrite(f);
+  for a := 0 to 4 do
+    for m := 1 to 3 do
+      begin
+        for n := 1 to 9 do
+          write(f, init_board[m][n] + a * 8, ' ');
+        writeln(f, init_board[m][10] + a * 8)
+      end;
+  close(f);
+
+  assign(f, 'XEPHINH5.TXT');
+  reset(f);
+  for m := 1 to 15 do
+    for n := 1 to 6 do
+      read(f, init_board[m][n]);
+  close(f);
+  assign(f, 'XEPHINH5.TXT');
+  rewrite(f);
+  for m := 1 to 15 do
+    begin
+      for a := 0 to 3 do
+        for n := 1 to 6 do
+          write(f, init_board[m][n] + a * 20, ' ');
+      for n := 1 to 5 do
+        write(f, init_board[m][n] + 80, ' ');
+      writeln(f, init_board[m][6] + 80);
+    end;
+  close(f);
+end.
diff --git a/THT/B/QG-2016/trigrid.c b/THT/B/QG-2016/trigrid.c
index 7f5a75f..15ad552 100644
--- a/THT/B/QG-2016/trigrid.c
+++ b/THT/B/QG-2016/trigrid.c
@@ -1,6 +1,5 @@
 #include <stdio.h>
 
-
 const long long TESTS[] = {4, 3, 5, 6, 111, 222, 3333, 4444, 55555, 666666,
                            7777777, 88888888, 999999999, 123456789123456789,
                            1000000000000000000};