您的位置:首页 > 其它

JZOJ 1361. 【2011.12.31普及模拟】抓捕嫌疑犯(suspect)

2018-01-27 19:08 260 查看

题目:

http://blog.csdn.net/qq_35786326/article/details/79191178


题意:

 求距离小Z为k的人有几位
分析:

 我们可以先排序,然后根据勾股定理求出距离,最后输出

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
struct node{
int x1,y1;double jl;
}h[50001];//结构体,以便我们之后通过一次快排将所有顺序排好
bool cmd(node x1,node y1)
{
return x1.jl>y1.jl||x1.jl==y1.jl&&x1.x1<y1.x1||x1.jl==y1.jl&&x1.x1==y1.x1&&x1.y1<y1.y1;//根据题目条件得出
}
int main()
{
freopen("suspect.in","r",stdin);
freopen("suspect.out","w",stdout);
int x,y,a[30001],b[30001],n,k;
scanf("%d%d",&x,&y);
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&h[i].x1,&h[i].y1);
h[i].jl=(double)sqrt(fabs(x-h[i].x1)*fabs(x-h[i].x1)+fabs(y-h[i].y1)*fabs(y-h[i].y1));//社会我勾股
}
sort(h+1,h+n+1,cmd);
int t=0;double sg=0;int w=1;
while(t!=k)//求出第一个人是谁
{
if(h[w].jl!=sg) t++,sg=h[w].jl;
w++;
}
t=0;
int i=w-1;
while(i<=n&&(double)sqrt(fabs(x-h[i].x1)*fabs(x-h[i].x1)+fabs(y-h[i].y1)*fabs(y-h[i].y1))==sg)//将所有的符合要求的嫌疑犯求出
t++,i++;
printf("%d\n",t);
for(int j=i-t;j<=i-1;j++) printf("%d %d\n",h[j].x1,h[j].y1);
fclose(stdin);
fclose(stdout);
return 0;
}


 



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  结构体 基础