称检测点查询

直接排序选择前三就行

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 210;

int n, X, Y;
struct Point
{
    int x, y, d;
    int id;
    bool operator< (const Point& t) const
    {
        if (d != t.d) return d < t.d;
        return id < t.id;
    }
}q[N];

int get_dist(int x1, int y1, int x2, int y2)
{
    int dx = x1 - x2;
    int dy = y1 - y2;
    return dx * dx + dy * dy;
}

int main()
{
    cin >> n >> X >> Y;
    for (int i = 0; i < n; i ++ )
    {
        int x, y;
        cin >> x >> y;
        q[i] = {x, y, get_dist(X, Y, x, y), i + 1};
    }
    sort(q, q + n);
    for (int i = 0; i < 3; i ++ ) cout << q[i].id << endl;
    return 0;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import functools

n, X, Y = map(int, input().split())

ans = []

for i in range(0, n):
    x, y = map(int, input().split())
    dis = pow((x - X), 2) + pow((y - Y), 2)
    ans.append([i, dis, x, y])

ans.sort(key = lambda x : x[1])

for i in range(0, 3):
    print(ans[i][0] + 1)

风险人群筛查

注意题意,逗留包括经过。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, k, t, xl, yl, xr, yr;
    cin>>n>>k>>t>>xl>>yl>>xr>>yr;
    int ans_d = 0, ans_j = 0;
    while(n--){
        int x, y;
        int cnt_k = 0, cnt = 0;
        for(int i = 0; i < t; i++){
            cin>>x>>y;
            if(x >= xl && x <= xr && y >= yl && y <= yr){
                cnt++;
            }else{
                cnt_k = max(cnt_k, cnt);
                cnt = 0;
            }
            cnt_k = max(cnt_k, cnt);
        }
        if(cnt_k > 0 ) ans_j++;
        if(cnt_k >= k) ans_d++;
    }
    cout << ans_j <<endl << ans_d <<endl;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
n, k, t, xl, yl, xr, yr = map(int, input().split())
ans_d = 0
ans_j = 0
for i in range(0, n):
    cnt_k = 0
    cnt = 0
    pos = list(map(int, input().split()))
    for j in range(0, t):
        x = pos[2 * j]
        y = pos[2 * j + 1]
        if x >= xl and x <= xr and y >= yl and y <= yr :
            cnt += 1
        else:
            cnt_k = max(cnt_k, cnt)
            cnt = 0
        cnt_k = max(cnt_k, cnt)
    if cnt_k > 0 : ans_j += 1
    if cnt_k >= k : ans_d += 1

print(ans_j)
print(ans_d)