当前位置:网站首页>@3-1 CCF 2020-09-1 称检测点查询
@3-1 CCF 2020-09-1 称检测点查询
2022-07-25 09:20:00 【叶萧白】
题目描述

样例

源代码
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
class Position
{
public:
int distance;
int num;
};
bool compare(Position a, Position b)
{
if (a.distance != b.distance)
return a.distance < b.distance;
else if (a.num != b.num)
return a.num < b.num;
}
int main()
{
int n, x, y;
int a, b;
Position d[201];
cin >> n >> x >> y;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
int distance = pow((a - x), 2) + pow((b - y), 2);
d[i] = {
distance,i + 1 };
}
sort(d, d + n, compare);
for (int i = 0; i < 3; i++)
cout << d[i].num << endl;
return 0;
}
关于这题
这里距离不用开方 直接记录平方就好 这里用的pow
这种要比较距离的同时 还要记录编号 最好用结构体 或者类
这里用的类 当然用pair也行
sort 是一个排序函数 排序方式 是自定义的compare
边栏推荐
猜你喜欢

将list集合的某一字段拼接单个String
![[HCTF 2018]admin](/img/d7/f0155c72d3fbddf0a8c1796a179a0f.png)
[HCTF 2018]admin

Unable to start debugging on the web server, the web server failed to find the requested resource

DVWA练习一 暴力破解

什么是单机、集群与分布式?

『每日一问』LockSupport怎么实现线程等待、唤醒

activemq--延迟投递和定时投递

数据控制语言(DCL)

Probe into Druid query timeout configuration → who is the querytimeout of datasource and jdbctemplate effective?

分布式一致性协议之Raft
随机推荐
~2 ccf 2022-03-1 未初始化警告
What are stand-alone, cluster and distributed?
[selected] from simple to deep, you will understand MQ principles and application scenarios
Write two channel (stereo) immediately Wav file
一文搞懂为什么要同时重写equals方法和hashCode方法+实例分析
office文件对应的Content-Type类型
The interviewer asked: how to prevent oversold? There are several ways to achieve it
[GYCTF2020]Ez_Express
ActiveMQ -- persistent mechanism
idea实用tips---如今将pom.xml(红色)改为pom.xml(蓝色)
Guangzhou has carried out in-depth "100 day action" to check the safety of self built commercial houses, and more than 2 million houses have been checked in two months
[De1CTF 2019]SSRF Me
Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground
~3 ccf 2022-03-2 出行计划
matplotlib数据可视化三分钟入门,半小时入魔?
Redis数据库基础
Activemq-- delayed delivery and scheduled delivery
~4.1 剑指 Offer 05. 替换空格
Analysis of five data structure principles of redis
【Nacos】NacosClient在服务注册时做了什么