一、题目
二、思路
按照题目要求模拟即可,即将数组的一个元素移动到尾
三、代码
#include <iostream>
using namespace std;
const int N = 20;
struct node {
int x1, y1, x2, y2, id;
node() {};
node ( int _x1, int _y1, int _x2, int _y2, int _id ) : x1(_x1), y1(_y1), x2(_x2), y2(_y2), id(_id) {}
}Node[N];
int n, m;
int get( int x, int y ) {
for ( int i = n; i >= 1; i-- ) {
if ( x >= Node[i].x1 && x <= Node[i].x2 && y >= Node[i].y1 && y <= Node[i].y2 )
return i;
}
return 0;
}
int main() {
cin >> n >> m;
for ( int i = 1; i <= n; i++ ) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
Node[i] = node( x1, y1, x2, y2, i );
}
while(m--) {
int x, y;
cin >> x >> y;
int flag = get(x, y);
if ( !flag ) cout << "IGNORED" << endl;
else {
cout << Node[flag].id << endl;
node temp = Node[flag];
for ( int i = flag; i < n; i++ ) //模拟窗口的移动
Node[i] = Node[i + 1];
Node[n] = temp;
}
}
return 0;
}