Advertisement
agul

WSO 2011 :: Problem D

Jul 7th, 2011
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.62 KB | None | 0 0
  1. uses
  2.     SysUtils, Math;
  3.    
  4. const
  5.     p=10037;
  6.     x:longint=257;
  7.  
  8. type
  9.     point=record
  10.         x,y,n:int64;
  11.     end;
  12.  
  13.     ap=array of point;
  14.  
  15. var
  16.     i,n,k,ii,j,tt:longint;
  17.     a:array[0..2020] of point;
  18.     h:array[0..p] of ap;
  19.     hh,aa:int64;
  20.     pp:point;
  21.     f:boolean;
  22.  
  23. function hash(s:string):int64;
  24.  
  25. var
  26.     i:longint;
  27.     c:int64;
  28.  
  29. begin
  30. result:=0;
  31. c:=1;
  32. for i:=1 to length(s) do begin
  33.         c:=(c*x) mod p;
  34.         inc(result,(ord(s[i])*c) mod p);
  35.         result:=result mod p;
  36. end;
  37. end;
  38.    
  39. begin
  40. reset(input,'input.txt');
  41. rewrite(output,'output.txt');
  42. read(n);
  43. for i:=1 to n do begin
  44.     read(a[i].x,a[i].y);
  45.     a[i].n:=i;
  46.     tt:=a[i].x+a[i].y+int64(a[i].x)*int64(a[i].y);
  47.     hh:=hash(inttostr(tt));
  48.     tt:=length(h[hh]);
  49.     setlength(h[hh],tt+1);
  50.     h[hh][tt]:=a[i];
  51. end;
  52. for i:=1 to n do
  53.     for j:=1 to n do begin
  54.         if (i=47) and ((j=9) or (j=88) or (j=110)) then begin
  55.             tt:=1;
  56.         end;
  57.         if (a[i].x=a[j].x) or (a[i].y=a[j].y) or
  58.             (abs(a[i].x-a[j].x)<>abs(a[i].y-a[j].y)) then continue else begin
  59.             f:=false;
  60.             pp.x:=a[i].x;
  61.             pp.y:=a[j].y;
  62.             tt:=pp.x+pp.y+pp.x*pp.y;
  63.             hh:=hash(inttostr(tt));
  64.             tt:=length(h[hh]);
  65.             dec(tt);
  66.             for ii:=0 to tt do
  67.                 if (pp.x=h[hh][ii].x) and (pp.y=h[hh][ii].y) then begin
  68.                     f:=true;
  69.                     k:=h[hh][ii].n;
  70.                     break;
  71.                 end;
  72.             if f then begin
  73.                 pp.x:=a[j].x;
  74.                 pp.y:=a[i].y;
  75.                 tt:=pp.x+pp.y+pp.x*pp.y;
  76.                 hh:=hash(inttostr(tt));
  77.                 tt:=length(h[hh]);
  78.                 dec(tt);
  79.                 for ii:=0 to tt do
  80.                     if (pp.x=h[hh][ii].x) and (pp.y=h[hh][ii].y) then begin
  81.                         write(a[i].n,' ',a[j].n,' ',k,' ',h[hh][ii].n);
  82.                         halt(0);
  83.                     end;
  84.             end;
  85.         end;
  86.     end;
  87. write('NO SOLUTION');
  88. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement