洛谷 P1003 [NOIP 2011 提高组] 铺地毯

没想到进国赛了,本来QT项目写的好好的现在又要开始康复训练了。。。
模拟题,我只对目标格子进行了判断,没去管框的其他位置,如果框到就更新,没框到就不用管。
整一个结构体存矩形左下角和右上角坐标,用来判断点是否被框。

AcCode:

#include<iostream>
#include<vector>
using namespace std;
struct square{
	int x1, y1, x2, y2;
};
vector<square> sq;

int main(){
	int N;
	cin >> N;
	while(N--){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		sq.push_back({a, b, a + c, b + d});
	}
	int tx, ty, ans = 0;
	cin >> tx >> ty;
	for(auto i = 0; i < sq.size(); i++){
		if(tx >= sq[i].x1 && tx <= sq[i].x2 && ty >= sq[i].y1 && ty <= sq[i].y2){
			ans = i + 1;
		}
	}
	cout << ans;
	return 0;
} 
posted @ 2025-05-07 00:50  Yuhhhhh  阅读(20)  评论(0)    收藏  举报