题目链接:https://www.luogu.org/problem/P1003
简单的贪心模拟
结构体存地毯的编号及两点坐标,从1开始扫面,判断这个点是否在地毯上或内部即可
因为顺序输入,所以最后一个符合条件的地毯一定是最上面的
代码:
#pragma GCC optimize(2) #include<stdio.h> #include<algorithm> #include<string.h> #include<string> #include<math.h> #include<set> #include<vector> #include<iostream> #include<queue> #include<map> #include<stack> using namespace std; const int maxn = 1e5 + 100; const int inf = 0x3f3f3f3f; typedef long long ll; struct node { int x, y, x1, y1, pos; }edge[maxn]; int u, v; int main() { //freopen("C://input.txt", "r", stdin); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> edge[i].x >> edge[i].y >> u >> v; edge[i].x1 = edge[i].x + u; edge[i].y1 = edge[i].y + v; edge[i].pos = i; } int _u, _v, _pos; cin >> _u >> _v; _pos = -1; for (int i = 1; i <= n; i++) { if (_u >= edge[i].x && _u <= edge[i].x1 &&_v >= edge[i].y && _v <= edge[i].y1) { _pos = edge[i].pos; } } cout << _pos << endl; return 0; }
洛谷P1003 铺地毯 贪心模拟
最新推荐文章于 2025-01-26 19:40:06 发布