题目链接:http://118.190.20.162/view.page?gpid=T112
记录自己没仔细审题,加上样例输出结果产生的错觉。
错误理解:误以为经过人数+逗留人数=n
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef struct {
int x;
int y;
}Point;
int main()
{
int n,k,t,xl,yd,xr,yu;
vector<int> ans;//标记逗留人数
vector<int> point[20+1];
cin >> n >> k >> t >> xl >> yd >> xr >> yu;
for(int i=0;i<n;i++){
for(int j=0;j<t;j++){
Point p;
cin >> p.x >> p.y;
if(p.x>=xl&&p.x<=xr&&p.y>=yd&&p.y<=yu){
point[i].push_back(1);
}else{
point[i].push_back(0);
}
}
}
// for(int i=0;i<n;i++){
// cout << "the " << i << endl;
// for(int j=0;j<t;j++){
// cout << point[i][j] << endl;
// }
// }
for(int i=0;i<n;i++){
int cnt=0;//标记是否连续 >k
int sum=0;
//cout << "the " << i << endl;
for(int j=0;j<t;j++){
if(point[i][j]==1){
cnt++;
if(cnt>=k){
ans.push_back(1);
break;
}
}
else cnt=0;
if(j==t-1){
ans.push_back(0);
}
// if(cnt=1){
// sum+=1;
// cout << "sum: " << sum << endl;
// if(sum>=k){
// ans.push_back(1);
// break;
// }
// }
// else sum=0;
// //cout << "::" << cnt << endl;
// if(point[i][j]==1){
// cnt=1;
// }else cnt=0;
// if(j==t-1){
// if(cnt==1){
// if(sum+1>=k) ans.push_back(1);
// }
// else ans.push_back(0);
// }
}
}
// for(int i=0;i<n;i++){
// cout << ans[i] << endl;
// }
int across=count(ans.begin(),ans.end(),1);
cout << n-across << endl;
cout << across << endl;
return 0;
}
正解:经过和逗留分别计数,也就是在经过的基础上才有逗留,而非(逗留+经过)=人口总数n
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef struct {
int x;
int y;
}Point;
int main()
{
int n,k,t,xl,yd,xr,yu;
int across=0,stay=0;
cin >> n >> k >> t >> xl >> yd >> xr >> yu;
for(int i=0;i<n;i++){
int cnt=0;
int _max=0;
int flag=0;
for(int j=0;j<t;j++){
int x,y;
cin >> x >> y;
if(x>=xl&&x<=xr&&y>=yd&&y<=yu){
cnt++;
flag=1;
if(cnt>_max){
_max=cnt;
}
}
else cnt=0;
}
if(flag) across++;
if(_max>=k) stay++;
}
cout << across << endl << stay << endl;
return 0;
}