一道有意思的簡單題

注意本題的資料最大到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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/232121.html
標籤:其他
