# SSL-ZYC arrest suspect

Main idea:
Little Z was ordered to follow a suspect. He walked all the way into a shopping mall and suddenly the man disappeared. Just as he was very anxious, the voice of the chief commander sounded in the earphone: listen, little Z. according to our surveillance, among the people around you, the suspect is the k far away from you. Please quickly confirm the target and carry out the arrest!
Give small Z's current front and everyone's position around, please help small Z to confirm who may be the suspect.
Note: there may be more than one suspect!

Ideas:
This question is a bit of a violent simulation. We first use Pythagorean theorem to find out the distance between each person and small Z, then quickly arrange, and finally find out the answer.
See my blog for details of Pythagorean theorem Action swordfish

code:

```#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int x,y,n,m,xx,yy,sum,k,a,b,i,j;
double f;
char c;

void sorts(int l,int r)  //Fast code
{
int i,j;
double t,z;
i=l;
j=r;
z=f[(i+j)/2];
do
{
while (f[i]<z) i++;
while (f[j]>z) j--;
if (i<=j)
{
t=f[i]; f[i]=f[j]; f[j]=t;
swap(a[i],a[j]);
swap(b[i],b[j]);
i++; j--;
}
}
while (i<j);
if (i<r) sorts(i,r);
if (j>l) sorts(l,j);
}

void sortt(int l,int r)  //Fast code, too
{
int i,j,z;
double t;
i=l;
j=r;
z=(i+j)/2;
do
{
while (a[i]<a[z]||(a[i]==a[z]&&b[i]<b[z])) i++;
while (a[j]>a[z]||(a[j]==a[z]&&b[j]>b[z])) j--;
if (i<=j)
{
swap(a[i],a[j]);
swap(b[i],b[j]);
i++; j--;
}
}
while (i<=j);
if (i<r) sortt(i,r);
if (j>l) sortt(l,j);
}

int main()
{
freopen("suspect.in","r",stdin);
freopen("suspect.out","w",stdout);
f=2147483646;
scanf("%d%d%d%d",&x,&y,&n,&m);
for (i=1;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
f[i]=sqrt((x-a[i])*(x-a[i])+(y-b[i])*(y-b[i]));  //Calculation distance of Pythagorean theorem
}
sorts(1,n);  //Quick row
sum=0;
for (i=n;i>=1;i--)  //Loo k ing for the person who is far away from the youngest Z
{
if (f[i]!=f[i+1]) sum++;
if (sum==m) break;
}
j=i-1;
sum=1;
while (f[j]==f[i])  //Record how many people are k away from him
{
j--;
sum++;
}
j++;
printf("%d\n",sum);
sortt(j,i);  //Quick row
for (int q=j;q<=i;q++)
printf("%d %d\n",a[q],b[q]);
scanf("%c",&c);
return 0;
}```

Posted by iluv8250 on Fri, 01 May 2020 22:45:23 -0700