C++ 编程实现地毯覆盖问题
#include <iostream>
#include <vector>
using namespace std;
struct Carpet {
int x;
int y;
int length_x;
int length_y;
};
int main() {
int n;
cin >> n;
vector<Carpet> carpets(n);
for (int i = 0; i < n; i++) {
cin >> carpets[i].x >> carpets[i].y >> carpets[i].length_x >> carpets[i].length_y;
}
int target_x, target_y;
cin >> target_x >> target_y;
int top_carpet = -1;
for (int i = n - 1; i >= 0; i--) {
if (target_x >= carpets[i].x && target_x <= carpets[i].x + carpets[i].length_x && target_y >= carpets[i].y && target_y <= carpets[i].y + carpets[i].length_y) {
top_carpet = i + 1;
break;
}
}
cout << top_carpet << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/paxd 著作权归作者所有。请勿转载和采集!