题目
新年到了,突然间,就在那美丽的一霎那,你好友和你(K个人)的周围满是礼物,你发扬你帅气的风格,让你的好友先拿,但是每个人只能拿当前离自己最近的礼物[当然如果有并列的多个礼物离你的距离相等(精确到小数后四位,所有运算均为去尾),这些礼物就都属于这个人]。现在你们所在的位置是原点(0,0),每个礼物的位置用坐标表示。现在告诉你每个礼物的坐标,还有每个礼物是谁送的。要你找出你的礼物离你多远,你能拿到多少礼物,这些礼物是谁送的。如果你拿不到礼物,请输出“555”
对于30%的数据 K≤N≤1000
对于所有的数据 K≤N≤100000
所有的坐标绝对值小于10^6
题解
模拟即可
点与点间的距离是很好算的了,精确到小数点后四位也是很好处理的了(*10000取整)。
处理读入的字符串时判断空格的位置即可,人的名字很长,不过只要求输出前21位。
提交编译错误了n次,错的是哪里呢?
val(copy(t,1,length(t)),y);//t打成了s
代码
var
n,k,i,j,x,y,ans,c:longint;
a,b:array[0..100500]of longint;
s:array [0..100500] of string;
t:ansistring;
d:double;
procedure qsort(l,r:longint);
var
i,j,key,key2,t:longint;
begin
if l>=r then exit;
i:=l;j:=r;
key:=a[(l+r) div 2];
key2:=b[(l+r) div 2];
repeat
while (a[i]<key)or(a[i]=key)and(b[i]<key2) do inc(i);
while (a[j]>key)or(a[j]=key)and(b[j]>key2) do dec(j);
if i<=j then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
s[0]:=s[i];s[i]:=s[j];s[j]:=s[0];
inc(i);dec(j);
end;
until i>j;
qsort(i,r);
qsort(l,j);
end;
begin
// assign(input,'find9.in');
// assign(output,'find.out');
// reset(input);rewrite(output);
readln(n,k);
for i:=1 to n do
begin
readln(t);
if length(copy(t,1,pos(' ',t)-1))>21 then s[i]:=copy(t,1,21) else
s[i]:=copy(t,1,pos(' ',t)-1);
delete(t,1,pos(' ',t));
if t[1]='-' then delete(t,1,1);
val(copy(t,1,pos(' ',t)-1),x);
delete(t,1,pos(' ',t));
if t[1]='-' then delete(t,1,1);
val(copy(t,1,length(t)),y);
a[i]:=trunc(sqrt(sqr(x)+sqr(y))*10000);
b[i]:=i;
end;
qsort(1,n);
i:=1;
while (i<=n)and(k>0) do
begin
if k=1 then break;
while (i<n)and(a[i]=a[i+1]) do inc(i);
dec(k);inc(i);
end;
if i>n then writeln('555') else
begin
k:=a[i];x:=i;
while (i<n)and(a[i]=a[i+1]) do inc(i);
writeln(k div 10000,' ',i-x+1);
for j:=x to i do
writeln(s[j]);
end;
// close(input);close(output);
end.