P1003 铺地毯

此题思想
根据初始点的位置,向上向右扩展出一个范围,然后进行递推即可。

#include<cstdio>
#include<iostream>
using namespace std;
int main() {
    int i, a[10001][4], n, x, y, f = -1;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
        a[i][2] += a[i][0];
        a[i][3] += a[i][1];
    }
    cin >> x >> y;
    for(i = n; i >= 1; i--) {
        if(a[i][0] <= x && a[i][1] <= y && a[i][2] >= x && a[i][3] >= y)
        {
            cout << i;
            f = 1;
            break;
        }
    }
    if (f == -1) {
        cout << f << endl;
    }
    return 0;
}
posted @ 2020-07-05 16:17  柠月与梦  阅读(161)  评论(0编辑  收藏  举报