Lay the carpet

一道有意思的简单题

在这里插入图片描述

注意本题的数据最大到10000,所以说开二维数组必定内存超限。

Title Description
In preparation for a unique award ceremony, the organizers spread some rectangular carpets over a rectangular area of the venue, which can be regarded as the first quadrant of the plane rectangular coordinate system. There are n carpets, numbered from 1 to n. These carpets are now laid parallel to the axis in the order of number from small to large, and the back carpet covers the carpet that has been laid in front. After the carpet is laid, the organizers want to know the number of the top carpet covering a point on the ground. Note: points on the rectangular carpet boundary and the four vertices are also covered by carpet.

Input Description:
The first line, an integer n, means there are n carpets in total.
In the next N lines, the I + 1 line represents the information of carpet number I, including four positive integers a, B, G, K. each two integers are separated by a space to represent the coordinates (a, b) of the lower left corner of the carpet to be laid and the length of the carpet along the X and Y axes.
Line n + 2 contains two positive integers x and y that represent the coordinates (x, y) of the point on the ground you are seeking.

Output Description:
Output a total of 1 line, an integer, indicating the number of the carpet required; if this is not covered by carpet, then output - 1.

Input
3
1 0 2 3
0 2 3 3
2 1 3 3
2 2

Output
3
意思就是说铺地毯,每次输入地毯在第一象限的起始点坐标和长和宽,然后最后输入
一个坐标让你判断这个点在第几号地毯上,注意,是地毯编号而不是层数。
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <set>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn=5e7+5;
const int Max = 0x3f3f3f;
const ll MOD = 1e9+7;
const int N = 10001;
int a[N];
vector<string> s;
bool st[N];
bool cmp(int a, int b) {
    
    
	return a > b;
}

struct node{
    
    
	int a, b, g, k;
};
int main() {
    
    
	IOS;
	node w[N];
	int n, x, y;
	cin >> n;
	for (int i = 1; i <= n; i++) 
		cin >> w[i].a >> w[i].b >> w[i].g >> w[i].k;
	cin >> x >> y;
	for (int i = n; i >= 1; i--){
    
    
		if (x>=w[i].a&&x<=w[i].a+w[i].g&&y>=w[i].b&&y<=w[i].b+w[i].k){
    
    
			cout << i <<endl;
			exit(0);
		}
	}
	cout << "-1" <<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45465598/article/details/110851130
lay