一、题目
二、解析
感觉用数组统计就完事了。
三、代码
#include <iostream>
#include <cstring>
#define MX 20000
using namespace std;
//n位居民
int n;
//连续k个判定为逗留
int k;
//每位居民有t个坐标
int t;
//矩形区域边界坐标
int Xl, Yd, Xr, Yu;
//统计经过和逗留的人数
int cntPass = 0;
int cntStay = 0;
//state:记录某一个居民的t个坐标是否在矩形区域中
//0:未在矩形区域中
//1:在矩形区域中
int state[MX];
void judge()
{
memset(state, 0, sizeof(state));
bool pass = false;
for (int i = 0; i < t; i++) {
int x, y;
cin >> x >> y;
if (x >= Xl && x <= Xr && y >= Yd && y <= Yu) {
pass = true;
state[i] += 1;
}
}
if (pass)
cntPass += 1;
//for(int i=0; i<t; i++)
//cout<<i<<" ";
//cout<<endl;
//
//for(int i=0; i<t; i++)
//cout<<state[i]<<" ";
//cout<<endl;
bool stay = false;
for (int i = 0; i < t - k + 1; i++) {
bool stayK = true;
for (int j = i; j < i + k; j++) {
if (state[j] == 0)
stayK = false;
}
if (stayK)
stay = true;
}
if (stay)
cntStay += 1;
}
int main()
{
cin >> n >> k >> t >> Xl >> Yd >> Xr >> Yu;
for (int i = 0; i < n; i++) {
judge();
}
cout << cntPass << endl;
cout << cntStay << endl;
return 0;
}
输入:
5 2 6 20 40 100 80
100 80 100 80 100 80 100 80 100 80 100 80
60 50 60 46 60 42 60 38 60 34 60 30
10 60 14 62 18 66 22 74 26 86 30 100
90 31 94 35 98 39 102 43 106 47 110 51
0 20 4 20 8 20 12 20 16 20 20 20
输出:
3
2