zoukankan      html  css  js  c++  java
  • LG. 1003 铺地毯

    LG. 1003 铺地毯

    题意分析

    给出平面中地毯的左上角坐标和长宽,然后给出一点(x,y)。求此点最上面是哪个地毯的编号,若没被覆盖则输出-1.

    将所有地毯的信息存在一个结构体中,由于后埔地毯在上面,在查询的时候,要倒着查询,若查询到就输出地毯编号,否则输出-1.

    代码总览

    #include <bits/stdc++.h>
    #define nmax 100005
    
    using namespace std;
    struct mes{
        int x,y,xexd,yexd;
    }item[nmax];
    int main()
    {
    
        int n;
        while(scanf("%d",&n) != EOF){
            for(int i = 0;i<n;++i){
                scanf("%d %d %d %d",&item[i].x,&item[i].y,&item[i].xexd,&item[i].yexd);
            }
            int x, y;
            bool isfind = false;
            scanf("%d %d",&x,&y);
            for(int i = n-1;i>=0;--i){
                if(x>=item[i].x && x<=item[i].x +item[i].xexd && y>=item[i].y && y<=item[i].y +item[i].yexd){
                    printf("%d
    ",i+1);
                    isfind = true;
                    break;
                }
            }
            if(!isfind) printf("-1
    ");
        }
        return 0;
    }
  • 相关阅读:
    数位DP
    组合
    卢卡斯Lucas&扩展卢卡斯
    [HNOI2014]道路堵塞
    [模板]三维凸包(无讲解)
    [CF526G]Spiders Evil Plan
    [CCPC2019 ONLINE]H Fishing Master
    [CCPC2019 ONLINE]E huntian oy
    [CF1037H]Security
    [CF1037F]Maximum Reduction
  • 原文地址:https://www.cnblogs.com/pengwill/p/7367063.html
Copyright © 2011-2022 走看看