CCF-CSP 201403-2窗口 简单模拟 满分题解
题目链接:201403-2窗口
思路:
- 用结构体存储两个点的坐标和层次
- 由于最后输入的位于最上层,因此从
n
开始遍历 - 当点击到当前层,当前层需要移动到最顶层,当前层的上面的层需要向下移动一层
- 定义
flag
作为是否有点击的标记
代码如下:
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 20;
int n,m;
struct {
int x1,y1,x2,y2;
int layer;//层次
}node[N];
int main()
{
cin>>n>>m;
//初始化
for(int i=1;i<=n;i++)
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
node[i] = {x1,y1,x2,y2,i};
}
while(m--)
{
int x,y;
bool flag = false;//用于判断是否点击到
cin>>x>>y;
//最后输入的在最上层
for(int i=n;i>=1;i--)
{
auto t = node[i];
if(x>=t.x1&&x<=t.x2&&y>=t.y1&&y<=t.y2)
{
cout<<t.layer<<endl;
flag = true;
//当前层次之上的,向下移动一层
for(int j=i;j<=n-1;j++)
{
node[j]=node[j+1];
}
node[n]=t;//当前层次到最上层
break;
}
}
//没有点击到
if(!flag)
{
cout<<"IGNORED"<<endl;
}
}
}