记录编号 |
24640 |
评测结果 |
AAAAAAAAAA |
题目名称 |
拯救奶牛贝希 |
最终得分 |
100 |
用户昵称 |
wo shi 刘畅 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.042 s |
提交时间 |
2011-04-13 09:10:01 |
内存使用 |
7.74 MiB |
显示代码纯文本
var
t,n,m,sx,sy,i,px,py,ans:longint;
a,b:array[0..1000000]of longint;
procedure sort(l,r: longint);
var
i,j,x,x1,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
x1:=b[(l+r) div 2];
repeat
while (a[i]<x)or((a[i]=x)and(b[i]<x1)) do
inc(i);
while (x<a[j])or((a[j]=x)and(x1<b[j])) do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
y:=b[i];
b[i]:=b[j];
b[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
function work(x,y,xx,yy:longint):longint;
var
l,d:longint;
begin
l:=0;
if odd(y) then
begin
d:=2*(xx-x);
if (yy>=y)and(yy<=y+d) then
begin
l:=d;
if not odd(yy) then dec(l);
end
else begin
if yy>y+d then l:=yy-y;
if yy<y then l:=d+y-yy;
end
end
else begin
dec(x);
dec(y);
d:=2*(xx-x);
if (yy>=y)and(yy<=y+d) then
begin
l:=d;
if not odd(yy) then dec(l);
end
else begin
if yy>y+d then l:=yy-y;
if yy<y then l:=d+y-yy;
end;
dec(l);
end;
work:=l;
end;
begin
assign(input,'rescuea.in'); reset(input);
assign(output,'rescuea.out'); rewrite(output);
readln(n,m);
readln(sx,sy);
for i:=1 to m do readln(a[i],b[i]);
sort(1,m);
ans:=maxlongint;
for i:=1 to m do
begin
if (sx<a[i])or((sx=a[i])and(sy<b[i])) then
t:=work(sx,sy,a[i],b[i])
else t:=work(a[i],b[i],sx,sy);
if t+1<ans then
begin
px:=a[i];
py:=b[i];
ans:=t+1;
end;
end;
writeln(px,' ',py);
writeln(ans);
close(input);
close(output);
end.