Skip to content

Instantly share code, notes, and snippets.

@McSinyx
Last active May 3, 2016 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McSinyx/9874b7a089aae88e358b422ac0cd3d03 to your computer and use it in GitHub Desktop.
Save McSinyx/9874b7a089aae88e358b422ac0cd3d03 to your computer and use it in GitHub Desktop.
Bài thi giải ba bảng C Tin học trẻ Thành phố Hà Nội năm học 2015 - 2016
(* 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.
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment