比赛 |
20110412pm |
评测结果 |
AWWWWWWWWW |
题目名称 |
拯救奶牛贝希 |
最终得分 |
10 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-04-12 15:26:48 |
显示代码纯文本
- var
- n,m,i,px,py,si,sj,now,ans:longint;
- a,b:array[0..20000]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 dis(xx,yy:longint):longint;
- var
- x,y,t,d:longint;
- begin
- x:=xx;
- y:=yy;
- t:=0;
- d:=(x-si)*2+sj;
- if sj mod 2=0 then
- begin
- inc(t,abs(d-y));
- inc(t,d-sj);
- end
- else begin
- if y>=d then inc(t,y-sj)
- else inc(t,d+d-2-y-sj)
- end;
- dis:=t+1;
- end;
-
- begin
- assign(input,'rescuea.in'); reset(input);
- assign(output,'rescuea.out'); rewrite(output);
- readln(n,m);
- readln(si,sj);
- for i:=1 to m do readln(a[i],b[i]);
- sort(1,m);
- ans:=maxlongint;
- for i:=1 to m do
- begin
- now:=dis(a[i],b[i]);
- if now<ans then
- begin
- px:=a[i];
- py:=b[i];
- ans:=now;
- end;
- end;
- writeln(px,' ',py);
- writeln(ans);
- close(input);
- close(output);
- end.