View Single Post
Old 16-08-2009, 01:42 PM   #18
Hồ sơ
nhan_lqd
Junior Member
 
nhan_lqd's Avatar
 
Tham gia ngày: Aug 2009
Số bài viết: 6
Tiền: 25
Thanks: 0
Thanked 10 Times in 2 Posts
nhan_lqd is on a distinguished road
Default Ðề: Một số bài toán cần nắm trong tin học

Code:
program chocolate;
const   fi='chocolate.inp';
        fo='chocolate.out';
var     L,W,S:int64;
        kq,T,d:integer;
procedure motep;
begin
  assign(input,fi);
  assign(output,fo);
  reset(input);
  rewrite(output);
end;
(*******************************)
procedure dongtep;
begin
  close(input);
  close(output);
end;
(********************************)
procedure docf;
begin
  readln(L,W,S);
end;
(*********************************)
procedure xuly;
var i,j:int64;
    kt:boolean;
begin
  kq:=-1;
  if S=L*W then kq:=0 else
  if ((S div L*L=S) and (S div L<=W)) or ((S div W*W=S) and (S div W<=L)) then
  kq:=1 else
  begin
    i:=S div 2;
    kt:=true;
    while kt do
    begin
      j:=s div i;
      if (i*j=S) and (((i<=W) and (j<=L)) or ((i<=L) and (j<=W))) then
      kq:=2;
      if (i<2) or (kq<>-1) then kt:=false else
      dec(i);
    end;
  end;
end;
(***********************************)
procedure inkq;
begin
  writeln(kq);
end;
(***********************************)
begin
  motep;
  readln(T);
  for d:=1 to T do
  begin
    docf;
    xuly;
    inkq;
  end;
  dongtep;
end.
nhan_lqd is offline   Trả Lời Với Trích Dẫn