202009-2风险人群筛查
题目描述
分析
没有复杂的算法。纯粹考简单的循环逻辑。
代码
#include <iostream>
using namespace std;
int main() {
int n;//input
int k;
int t;
int xl,xr,yd,yu;
cin >> n;
cin >> k;
cin >> t;
cin >> xl;
cin >> yd;
cin >> xr;
cin >> yu;
int count_via = 0;
int count_stay = 0;
int i,j;
int x,y;
// 遍历n个人
for (i = 0; i < n; i++){
int stay = 0;
bool stay_flag = false;
bool via_flag = false;
//遍历t个地点
for (j = 0; j < t; j++){
cin >> x;
cin >> y;
//已经逗留则无需判断
if (stay_flag){
continue;
}
//如果在矩形内
if (xl <= x && x <= xr && yd <= y && y <= yu){
via_flag = true;//一定经过
stay += 1;//停留天数+1
if (stay >= k){//停留足够天数则置flag
stay_flag = true;
}
}
else {//不在矩形内stay置0,重新计数
stay = 0;
}
}
//对一个人的行程分析完毕,进行计数
if (via_flag){
count_via++;
}
if(stay_flag){
count_stay++;
}
}
cout << count_via << "\n";
cout << count_stay << "\n";
return 0;
}