题目链接
- 202009-2 风险人群筛查
题目描述
求解思路
- 本题的数据量并不大,直接模拟即可。
x
和y
表示每次读取的坐标点。res1
表示经过高风险场地的人数,res2
表示在高风险场地停留的人数。s
用来记录连续在高风险场地停留的点数。r1
表示是否经过高风险场地,r2
表示是否在高风险场地逗留。
实现代码
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);int n = in.nextInt();int k = in.nextInt();int t = in.nextInt();int xl = in.nextInt();int yd = in.nextInt();int xr = in.nextInt();int yu = in.nextInt();int x, y;int res1 = 0, res2 = 0;int s;for (int i = 0; i < n; i++) {boolean r1 = false, r2 = false;s = 0;for (int j = 0; j < t; j++) {x = in.nextInt();y = in.nextInt();if (x >= xl && x <= xr && y >= yd && y <= yu) {s ++;r1 = true;} else {s = 0;}if (s >= k) {r2 = true;}}if (r1) {res1 ++;}if (r2) {res2 ++;}}System.out.println(res1);System.out.println(res2);}
}