CFF review question 20200-2 Screening of risk groups

Question number: 202009-2
Question name: Screening of risk groups
Time limit: 1.0s
Memory limit: 256.0MB
Question description:

Question background

After an epidemic breaks out in a certain place, out of the principle of "check everything you need", we would like to notify all residents who have recently passed through this high-risk area to participate in nucleic acid testing.

Problem Description

Analyzing location records is a simple and effective way to find residents who pass 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 i at time.
The high-risk area can be abstracted as a rectangular area (including boundaries). 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 located within a rectangle (including the boundary), it means that the resident 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 a high-risk area. It should be noted that when determining passing and staying, we only care about the t coordinates in the location record, without considering where the resident is between time i and i+1.

Given the scope of the high-risk area and the location records of n residents in the past t moments, try to count 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.

Input format

Enter a total of n+1 lines.

The first line contains seven space-separated integers n, k, t, xl, yd, xr, and yu, with the meanings described above.

Next n lines, each line contains 2t integers separated by spaces, which in order represent the location records (x1, y1), (x2, y2), ⋯, (xt, yt) of a resident in the past t moments.

Output format

There are two lines of output, each line contains an integer, representing the number of people passing through the high-risk area and the number of people who have stayed in the high-risk area respectively.

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 in the red mark in the figure below, the first three location records passed through the high-risk area;
but the third location record (the upper left curve in the figure) was only in the high-risk area at one time and did 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 Description:
This location record has passed through a high-risk area, but has only been in it for at most two consecutive moments, and does not meet the stay conditions.

Evaluation case scale and convention:
All test points satisfy 1≤n≤20, 1≤k≤t≤103, all coordinates are integers and the absolute value does not exceed 106.

Show results

Insert image description here
Sample 1 output
Insert image description here

Problem-solving ideas

1. The focus of this question

Just focus on the coordinate data.

2. Problem-solving ideas

By analyzing the questions, we can know:
1) The coordinates of the four points in the high-risk rectangular area are:
(xl,yu), (xr,yu), (xl,yd), (xr,yd).
Therefore, as long as the resident coordinates xl =< xt <= xr and yd =< yt <= yu, they are within the high-risk area.

2) Determination of passing and staying
: passing: one coordinate is located within the rectangle (including the boundary);
staying: K or more consecutive coordinates are located within the rectangle (including the boundary).

3) How to determine K consecutive ones?
Count, if it is in the high-risk area, +1, otherwise -1, determine whether the count is greater than or equal to K, and then determine whether to stay.
Only if it lasts K times or more, the count value will be greater than or equal to K, and the stay can be judged.

Code display

/*CFF试题202009-2,试题名称:风险人群筛查 Time:2021-0221*/
/*主要关注点在连续计数和区域判断
	连续计数需要连续K个以上才算逗留
	区域判断:即坐标 xl =< xt <= xr,yd =< yt <= yu*/ 
/*标准源码获取:清月学习社*/
#include <iostream>
#include<stdio.h>
using namespace std; 


int main()
{
    
    
    int n, k, t, xl, yd, xr, yu;
	
	cin >> n >> k >> t >> xl >> yd >> xr >> yu;	
	
	int pass_count = 0;		// 经过计数 
	int stay_count = 0; 	// 逗留计数 
	
	// n个居民的坐标 
    for(int i=0;i<n;i++)
    {
    
    
    	int xt, yt;			// 居民实时坐标点;
		int count = 0;		// 连续点计数 
		
		bool flag1 = false;	// 经过判定 
		bool flag2 = false;	// 逗留判定 
		
		// 第i个居民坐标的判断 
        for(int j=0;j<t;j++)
		{
    
    
			cin >> xt >> yt;// 输入实时数据
			
			// 有坐标在高危区域内 
			if((xt>=xl && xt<=xr) && (yt>=yd && yt<=yu)) 
			{
    
    
				count++;
				flag1 = true;// 经过 
				
				// 如果连续有K个坐标在内 
				if(count >= k)
				{
    
    
					flag2 = true;// 逗留 
				}
			 } 
			 else
			 {
    
    
			 	count = 0;// 归零 
			 }						
		 } 
		
		// 经过和逗留计数 
		if(flag1)
			pass_count++;
		if(flag2)
			stay_count++;
    } 
	cout << pass_count << endl << stay_count;            	 
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43658159/article/details/113919767