topic
Question No.: | 202009-2 |
Question name: | Risk population screening |
time limit: | 1.0s |
Memory limit: | 256.0MB |
Topic background
After the outbreak of an epidemic in a certain place, out of the principle of "all inspections should be done", we want to notify all residents who have recently passed through the high-risk area to participate in nucleic acid testing.
Problem Description
Analyzing location records is a simple and effective way to find out residents who have passed through high-risk areas.
Specifically, a resident's location record contains t plane coordinates, where (x 1 ,y 1 ), (x 2 ,y 2 ), ..., (x n ,y n ) represent the resident's current location.
The high-risk area can be abstracted as a rectangular area (including the boundary), the coordinates of the lower left corner and the upper right corner are (x l , y d ) and (x r , y u ) respectively, satisfying x l < x r and y d < y u .
Consider the location record of a resident, if one of the coordinates is within the rectangle (including the boundary), it means that the resident has passed the high-risk area; further, if one or more of the consecutive coordinates are within the rectangle (including the boundary), then The resident is believed to have stayed in a high-risk area. It should be noted that we only care about the k coordinates in the location record when determining passing and staying, and do not need to consider where the resident is between time i and i + 1.
Given the range of high-risk areas and the location records of n residents at past t moments, try to count the number of people who have passed through high-risk areas and the number of people who have stayed in high-risk areas.
Input format
Input a total of n + 1 lines.
The first line contains the seven integers n, k, t, xl, yd, xr, and yu separated by spaces, with the meanings described above.
The next n lines, each containing 2t integers separated by spaces, represent the location records of a resident in the past moments in sequence.
Output format
The output consists of two lines, each with an integer, respectively representing the number of people passing through the high-risk area and the number of people who have stayed in the high-risk area.
Sample input 1
5 2 6 20 40 100 80 100
80 100 80 100 80 100 80 100 80 100 80 60 50 60 46 60
42 60 38 60 34 60 30 10 60 14 62 18 66 2 2 74 26
86 30 100 90 31
94 35 98 39 102 43 106 47 110 51
0 20 4 20 8 20 12 20 16 20 20 20
Sample output 1
3
2
Explanation of Example 1
As shown in the red mark in the figure below, the first three location records have passed through high-risk areas;
but the third location record (upper left curve in the figure) is only in a high-risk area at one time, and does not meet the stay conditions.
Sample input 2
1 3 8 0 0 10 10
-1 -1 0 0 0 0 -1 -1 0 0 -1 -1 0 0 0 0
Sample output 2
1
0
Example 2 explains
that the location record has passed through a high-risk area, but it can only be located in it for at most two consecutive moments, which does not meet the stay conditions.
Evaluation case scale and agreement
All test points satisfy 1 ≤ n ≤ 20, 1 ≤ k ≤ t ≤ 10 30 , all coordinates are integers and the absolute value does not exceed 10 6 .
code
# 输入n,k,t,xl,yd,xr,yu
n,k,t,xl,yd,xr,yu = map(int,input().split())
# 记录经过或逗留人数列表
pass_stay = [0,0]
# 循环输入并判断
for i in range(n):
seat = list(map(int,input().split()))
# 连续最多逗留时长和此次逗留时长初始化
max_count = 0
count = 0
# 遍历时间
for j in range(t):
# 判断是否处于区域内部
if xl <= seat[j * 2] and seat[j * 2] <= xr and yd <= seat[j * 2 + 1] and seat[j * 2 + 1] <= yu:
count += 1
# 判断是否更新最长逗留时间
if count > max_count:
max_count = count
else:
count = 0
# 在经过高风险地区时 判断该居民始经过还是逗留
if max_count != 0:
if max_count < k:
pass_stay[0] += 1
else:
pass_stay[0] += 1
pass_stay[1] += 1
# 输出结果
print(pass_stay[0])
print(pass_stay[1])