CCF CSP 202009-2 Risk population screening (100 points in C++ language)

1. Question link: CCF 202009-2 Risk population screening

Question No.: 202009-2
Question name: Risk population screening
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

topic background

After the outbreak of an epidemic in a certain place, we would like to notify all residents who have recently passed through the high-risk area to participate in nucleic acid testing out of the principle of "all tests should be done".

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 (x1, y1), (x2, y2), ..., (xt, yt), where (xi, yi) represents the location of the resident at moment i.
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 (xl, yd) and (xr, yu) respectively, satisfying xl<xr and yd<yu.

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 through the high-risk area; further, if k or more consecutive coordinates are located within the rectangle (including the boundary), It is considered that the resident has stayed in the high-risk area . It should be noted that we only care about the t coordinates in the location record when judging passing and staying , without considering 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 (x1, y1), (x2, y2), ⋯, (xt, yt) of a resident in the past t moments in sequence.

output format

The output consists of two lines, and each line is an integer, respectively representing the number of people who have passed 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 22 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

Example 1 description

As shown by the red mark in the figure below, the first three location records have passed through high-risk areas;
but the third location record (the upper left curve in the figure) is only in the high-risk area at one time, and does not meet the stay conditions.

p2.png

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 Description

The location record has passed through a high-risk area, but it can only be in it for two consecutive moments at most, and the stay condition is not met.

Evaluation use case scale and agreement

All test points satisfy 1≤n≤20, 1≤k≤t≤10 3 , all coordinates are integers and the absolute value does not exceed 10 6 .

2. Problem analysis:

After reading the question analysis, the difficulty of this question lies in judging the continuous \color{red}\large{\bold{continuous}}Consecutive k or more coordinates are located within the rectangle (including the boundary), that is,whether there is a stay in a high-risk area. What I use here is to directly count the number of coordinates passing through the high-risk area through input stream processing, then iterate the maximum value, and finally judge whether a resident is staying. It should be noted that prev is initialized to time t to ensure that statistics will not be performed for the first time, and it will always be assigned the latest coordinate time passing through the high-risk area. The cnt variable indicates the number of coordinates that have continuously passed through the high-risk area.

3. C++ language program implementation:

#include <bits/stdc++.h>

using namespace std;
bool in_danger_area(int &xl,int &yd,int &xr,int &yu,int x,int y)
{
    
    
    if (x>=xl&&x<=xr&&y>=yd&&y<=yu)
    {
    
    
        return true;
    }
    else
    {
    
    
        return false;
    }
}
int main()
{
    
    
    int n,k,t,xl,yd,xr,yu,xt,yt,passed=0,leaved=0,cnt,prev,adjacent_max;
    scanf("%d%d%d%d%d%d%d",&n,&k,&t,&xl,&yd,&xr,&yu);
    for (int i=0; i<n ; ++i )
    {
    
    
        bool is_in=false;
        prev=t;
        cnt=1,adjacent_max=0;
        for (int j=0; j<t ; ++j )
        {
    
    
            scanf("%d%d",&xt,&yt);
            if (in_danger_area(xl,yd,xr,yu,xt,yt))
            {
    
    
                if (j-prev==1)
                {
    
    
                    adjacent_max=max(++cnt,adjacent_max);
                }
                else
                {
    
    
                    cnt=1;
                }
                prev=j;
                is_in=true;
            }
        }
        if (is_in)
        {
    
    
            ++passed;
        }
        if (adjacent_max>=k)
        {
    
    
            ++leaved;
        }
    }
    printf("%d\n%d",passed,leaved);
    return 0;
}

4. Submit AC results:

insert image description here

Guess you like

Origin blog.csdn.net/m0_46223009/article/details/125191365