题目
分析
本来是想用两个二维数组的,但是我发现每一行输入的数据只需要使用一次就行了,可以不使用数组存储,所以就仅仅使用了两个临时变量,这题想明白了还是挺简单的。
代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n=s.nextInt();
int k=s.nextInt();
int t=s.nextInt();
int xl=s.nextInt();
int yd=s.nextInt();
int xr=s.nextInt();
int yu=s.nextInt();
int count1 = 0, count2 = 0, flag1 = 0, flag2 = 0, last = 0;
for(int i=0;i<n;i++)
{
for (int j=0;j<t;j++)
{
int tempX=s.nextInt();
int tempY=s.nextInt();
if(flag2==1)
continue;
if(tempX >= xl && tempX <= xr && tempY >= yd && tempY <= yu)
{
flag1 = 1;
last++;
}
else{
last = 0;
}
if(last >= k)
{
flag2 = 1;
}
}
count1+=flag1;
count2+=flag2;
flag1 = 0;
flag2 = 0;
last = 0;
}
System.out.println(count1);
System.out.println(count2);
}
}