202009-1 对称检测点查询
题目:202009-1
题目分析:
给定一群点的坐标,求出距离某点最近的3个点的坐标。
纯模拟即可。
AC代码:
// -*- coding:utf-8 -*-
// File : 202009-1.cpp
// Time : 2024/03/23
// Author : wolf
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
// 读入与计算
int n, x, y;
scanf("%d %d %d", &n, &x, &y);
int m[n];
for (int i = 0; i < n; i++)
{
int a, b;
scanf("%d %d", &a, &b);
int d = pow(abs(x - a), 2) + pow(abs(y - b), 2);
m[i] = d;
}
// 简单版top_k问题,这里是top3,使用if_choose数组做标记,遍历三次,分别找到单次最小的
bool if_choose[n];
for (int i = 0; i < n; i++)
{
if_choose[i] = 0;
}
for (int k = 0; k < 3; k++)
{
int ans;
int minnum = 8e6 + 1;
for (int i = 0; i < n; i++)
{
if (if_choose[i] == 0 && m[i] < minnum)
{
minnum = m[i];
ans = i;
}
}
if_choose[ans] = 1;
printf("%d\n", ans + 1);
}
return 0;
}
202009-2 风险人群筛查
题目:202009-2
题目分析:
给定一个矩形范围,给定n个人的坐标轨迹,有1次在矩形范围内称为“经过”连续k次在矩形范围内称为“逗留”,问有几个人“经过”,有几个人“逗留”。
模拟即可。
AC代码:
// -*- coding:utf-8 -*-
// File : 202009-2.cpp
// Time : 2024/03/23
// Author : wolf
#include <iostream>
using namespace std;
int main()
{
int n, k, t, x1, y1, x2, y2;
scanf("%d %d %d %d %d %d %d", &n, &k, &t, &x1, &y1, &x2, &y2);
int pass = 0;
int stay = 0;
for (int i = 0; i < n; i++)
{
bool if_pass = 0;
bool if_stay = 0;
int stay_time = 0;
for (int j = 0; j < t; j++)
{
int x, y;
scanf("%d %d", &x, &y);
if (x >= x1 && y >= y1 && x <= x2 && y <= y2)
{
if_pass = 1;
stay_time++;
}
else
{
stay_time = 0;
}
if (stay_time >= k)
if_stay = 1;
}
if (if_pass)
pass++;
if (if_stay)
stay++;
}
printf("%d\n%d", pass, stay);
return 0;
}