题意:给你一个矩阵范围和 n 个人的 t 个位置,让你判断有多少人进入过这个矩阵,又有多少人连续 k 个位置一直处于矩阵内。直接遍历统计一下即可,注意逗留的人也算经过。
代码实现:
import java.util.*;
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 [] f = new int[10];
for(int i = 1; i <= 4; i ++)
f[i] = in.nextInt();
int ans_j = 0, ans_d = 0, w = 0;
while(n-->0){
int tmp = 0, dl = 0, jg = 0;
for(int i = 1; i <= t; i ++){
int a = in.nextInt();
int b = in.nextInt();
if(f[1]<=a&&a<=f[3] && f[2]<=b&&b<=f[4]) {
jg = 1;
tmp ++;
if(k<=tmp) dl = 1;
}
else tmp = 0;
}
ans_d += dl;
ans_j += jg;
}
System.out.println(ans_j);
System.out.println(ans_d);
in.close();
}
}