博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
202009-01 ccf-csp 检测点查询(满分代码)
阅读量:302 次
发布时间:2019-03-03

本文共 2230 字,大约阅读时间需要 7 分钟。

作者:its_ycm 来源:CSDN 原文:https://blog.csdn.net/its_ycm/article/details/109389578 版权声明:本文为博主原创文章,转载请附上博文链接!

试题编号: 202009-1

试题名称: 称检测点查询
时间限制: 1.0s
内存限制: 256.0MB
问题描述:
题目背景
2020 年 6 月 8 日,国务院联防联控机制发布《关于加快推进新冠病毒核酸检测的实施意见》,提出对“密切接触者”等八类重点人群“应检尽检”,其他人群“愿检尽检”。

问题描述

某市设有 个核酸检测点,编号从 到 ,其中 号检测点的位置可以表示为一个平面整数坐标

为方便预约核酸检测,请根据市民所在位置 ,查询距其最近的三个检测点。

多个检测点距离相同时,编号较小的视为更近。

输出格式

输出共三行,按距离从近到远,依次输出距离该市民最近的三个检测点编号。

样例输入1

3 2 2
2 2
2 3
2 4
Data
样例输出1
1
2
3
Data
样例输入2
5 0 1
-1 0
0 0
1 0
0 2
-1 2
Data
样例输出2
2
4
1

评测用例规模与约定

全部的测试点满足,,所有坐标均为整数且绝对值不超过 。

在这里插入图片描述

用结构体数组的解法:

#include
using namespace std;const int N=201;struct node{
int id; int dis;};bool cmp(struct node n1,struct node n2){
if(n1.dis==n2.dis) return n1.id
>n>>a>>b; int x,y; for(int i=0;i
>x>>y; v=(a-x)*(a-x)+(b-y)*(b-y); nod[i].dis=v; nod[i].id=i+1; } sort(nod,nod+n,cmp); for(int i=0;i<3;++i) cout << nod[i].id << endl; return 0;}

用STL的解法:

#include
using namespace std;struct node{
int id; int dis; bool operator < (const node& n) const{
if(dis==n.dis) return id>n.id; else return dis>n.dis; }};int main(){
priority_queue
q; map
m; int n,a,b,t; cin>>n>>a>>b; int x,y; for(int i=0;i
>x>>y; t=(a-x)*(a-x)+(b-y)*(b-y); m[i+1]=t; } node nod; for(map
::iterator it=m.begin();it!=m.end();++it){
nod.id = it->first; nod.dis = it->second; q.push(nod); } int j=1; while(j<=3){
nod=q.top(); q.pop(); cout << nod.id << endl; j++; } return 0;}

用2个普通数组存数据

#include
using namespace std;const int N = 200;int dis[N+1];int d[N+1];//放距离的复制版本int main(){
int n,x,y; cin>>n>>x>>y; int a,b; for(int i=1;i<=n;++i){
cin>>a>>b; dis[i] = (a-x)*(a-x)+(b-y)*(b-y); d[i] = dis[i]; } sort(dis,dis+n+1); for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j) if(dis[i]==d[j]){
cout << j << endl; d[j]=-1; break; } if(i==3) break; } return 0;}

用普通数组暴力解法

#include
using namespace std;int a[200][2];int b[200][2];int c[3];int main(){
int i,n,x,y,j,m,k=0,temp; cin>>n>>x>>y; for(i=0;i
>a[i][0]>>a[i][1]; b[i][0]=(x-a[i][0])*(x-a[i][0])+(y-a[i][1])*(y-a[i][1]); b[i][1]=i+1; } for(i=0;i
你可能感兴趣的文章