【题解】P1003 铺地毯
题面
前言
云落第一眼,矩形面积并?
第二眼,二维树状数组矩修单查
正文
第三眼,就查一个点啊,直接枚举每次更新对 \((x,y)\) 是否有效即可
难以论说
代码实现
可以用结构体存入四个坐标以及编号
然后直接循环遍历即可
代码
#include<iostream>
#define x1 x_1
#define y1 y_1
#define x2 x_2
#define y2 y_2
#define endl '\n'
#define int long long
using namespace std;
const int maxn=1e4+10;
int n,x,y;
struct node{
int idx,x1,y1,x2,y2;
}p[maxn];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
int a,b,g,k;
cin>>a>>b>>g>>k;
p[i]={i,a,b,a+g,b+k};
}
cin>>x>>y;
int ans=-1;
for(int i=1;i<=n;i++){
if(x>=p[i].x1&&x<=p[i].x2&&y>=p[i].y1&&y<=p[i].y2){
ans=p[i].idx;
}
}
cout<<ans<<endl;
return 0;
}
后记
主打一个不要陷入思维误区……
完结撒花!