思路

遍历判断所求位置是否在某一地毯上,最后所在的地毯即是答案。

代码

#include <iostream>
#include <vector>


bool IsIntheBlanket(std::vector<int> &region,
                  int l1,int l2)
{
    int xUpLimit=region[0]+region[2];
    //std::cout<<region[0]<<","<<region[2]<<std::endl;
    int yUpLimit=region[1]+region[3];
    bool isInX=(l1>=region[0]&&l1<=xUpLimit);
    bool isInY=(l2>=region[1]&&l2<=yUpLimit);
    bool isIn=isInX&&isInY;
    return isIn;  
}

int main()
{
    int n;
    int result=-1;
    std::cin>>n;
    std::vector<std::vector<int>> region(n,std::vector<int>(4));
    int x1,x2,y1,y2;
    for(int i=0;i<n;i++)
    {
        std::cin>>x1>>y1>>x2>>y2;
        region[i][0]=x1;
        region[i][1]=y1;
        region[i][2]=x2;
        region[i][3]=y2;
        // std::cout<<region[i][0]<<","<<region[i][2]<<std::endl;
    }
    int l1,l2;
    std::cin>>l1>>l2;
    //std::cout<<l1<<","<<l2<<std::endl;
    for(int i=0;i<n;i++)
    {
        bool isInBlanket=IsIntheBlanket(region[i], l1,l2);
        if(isInBlanket) result=i+1;
    }
    std::cout<<result<<std::endl;
    
    return 0;
}