题目大意
给出一个疫区,再给出n个人各t个时刻的行踪。如果某人某时刻在疫区内,则算经过;如果某人连续都k个时间都在疫区内,则算停留。求这n 个人中经过和停留疫区的各多少人。
解题思路
对于“经过”审题不清;学会灵活应用bool类型变量;
#include<stdio.h>
using namespace std;
int n, k, t, xl, yd, xr, yu,x,y;
int main(){
scanf("%d%d%d%d%d%d%d", &n, &k, &t, &xl, &yd, &xr, &yu);
int ans1 = 0, ans2 = 0;
for (int i = 1; i <= n; i++){
int t2=0, temp= 0;
bool flag = false;
for (int j = 1; j <= t; j++){
scanf("%d%d", &x, &y);
if (x >= xl&&x <= xr&&y >= yd&&y <= yu){
temp++;
t2++;//判断是否在此区域,如果在则+1;不在=0;
if (t2 >= k)
flag = true;//flag=true代表逗留
}
else
t2=0;
}
if (temp) ans1++;
if (flag) ans2++;
}
printf("%d\n%d", ans1,ans2);
return 0;
}