当前位置 博文首页 > ApocalypseTq的博客:P1003 [NOIP2011 提高组] 铺地毯 题解

    ApocalypseTq的博客:P1003 [NOIP2011 提高组] 铺地毯 题解

    作者:[db:作者] 时间:2021-09-23 15:40

    本题直接搜索貌似会TLE,于是可以扫每一个给出的方格,查看所查点是否在范围内,不断叠加并记录即可。

    代码如下:

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int n,nx,ny,ans=-1;
    int sx[10001],sy[10001],lx[10001],ly[10001];
    bool yn(int x,int y,int lx,int ly)
    {
        if(nx>=x && ny>=y && nx<=x+lx && ny<=y+ly)//边界判断
        {
            return true;
        }
        return false;
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d%d",&sx[i],&sy[i],&lx[i],&ly[i]);
        }
        scanf("%d%d",&nx,&ny);
        for(int i=1;i<=n;i++)
        {
            if(yn(sx[i],sy[i],lx[i],ly[i])==true)
            {
                ans=i;//答案叠加
            }
        }
        cout<<ans;
        return 0;
    }
    cs