比赛 20110412pm 评测结果 AWWWWWWWWW
题目名称 拯救奶牛贝希 最终得分 10
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-04-12 15:26:48
显示代码纯文本
  1. var
  2. n,m,i,px,py,si,sj,now,ans:longint;
  3. a,b:array[0..20000]of longint;
  4.  
  5. procedure sort(l,r: longint);
  6. var
  7. i,j,x,x1,y: longint;
  8. begin
  9. i:=l;
  10. j:=r;
  11. x:=a[(l+r) div 2];
  12. x1:=b[(l+r) div 2];
  13. repeat
  14. while (a[i]<x)or((a[i]=x)and(b[i]<x1)) do
  15. inc(i);
  16. while (x<a[j])or((a[j]=x)and(x1<b[j])) do
  17. dec(j);
  18. if not(i>j) then
  19. begin
  20. y:=a[i];
  21. a[i]:=a[j];
  22. a[j]:=y;
  23.  
  24. y:=b[i];
  25. b[i]:=b[j];
  26. b[j]:=y;
  27. inc(i);
  28. j:=j-1;
  29. end;
  30. until i>j;
  31. if l<j then
  32. sort(l,j);
  33. if i<r then
  34. sort(i,r);
  35. end;
  36.  
  37. function dis(xx,yy:longint):longint;
  38. var
  39. x,y,t,d:longint;
  40. begin
  41. x:=xx;
  42. y:=yy;
  43. t:=0;
  44. d:=(x-si)*2+sj;
  45. if sj mod 2=0 then
  46. begin
  47. inc(t,abs(d-y));
  48. inc(t,d-sj);
  49. end
  50. else begin
  51. if y>=d then inc(t,y-sj)
  52. else inc(t,d+d-2-y-sj)
  53. end;
  54. dis:=t+1;
  55. end;
  56.  
  57. begin
  58. assign(input,'rescuea.in'); reset(input);
  59. assign(output,'rescuea.out'); rewrite(output);
  60. readln(n,m);
  61. readln(si,sj);
  62. for i:=1 to m do readln(a[i],b[i]);
  63. sort(1,m);
  64. ans:=maxlongint;
  65. for i:=1 to m do
  66. begin
  67. now:=dis(a[i],b[i]);
  68. if now<ans then
  69. begin
  70. px:=a[i];
  71. py:=b[i];
  72. ans:=now;
  73. end;
  74. end;
  75. writeln(px,' ',py);
  76. writeln(ans);
  77. close(input);
  78. close(output);
  79. end.