zoukankan      html  css  js  c++  java
  • 洛谷 P1003 铺地毯

    嗯....

     

    一道比较水的模拟题..

     

    刚拿到题的时候被它的数据范围吓到了,二维数组不可能开那么大啊,可是一边做发现测试数据太水 ...

     

    先看一下题吧:https://www.luogu.org/problemnew/show/P1003

    ---------貌似说明没有用,本来我们就是后面的自动将前面的覆盖..

    第一次只过了3个点,本来以为是MLE,没想到是WA....然后才发现自己居然只判断了一边的边界,另一边的边界没有判断...

    思路:

      首先一次性地将所有的东西全都输入,然后进行逆序查找,会节省一些时间,如果发现g[x][y]点上覆盖着地毯,直接输出即可(这与题中的说明有关...

     

    下面是AC代码...

     1 #include<cstdio>
     2 #include<iostream>
     3 
     4 using namespace std;
     5 
     6 
     7 int g[10005][10005];
     8 int a[10005][4];
     9 int x, y;
    10 
    11 int main(){
    12     int n;
    13     scanf("%d", &n);
    14     for(int i = 1; i <= n; i++){
    15         for(int j = 1; j <= 4; j++){
    16             scanf("%d", &a[i][j]); 
    17         }
    18     }
    19     scanf("%d%d", &x, &y);//全部读入 
    20     for(int i = n; i >= 1; i--){//逆序查找(将地毯从上往下掀 
    21         if(x >= a[i][1] && x <= a[i][1] + a[i][3] && y >= a[i][2] && y <= a[i][2] + a[i][4]){//注意一共有四个边界 
    22             printf("%d", i);
    23             return 0;
    24         }
    25     }
    26     printf("-1");//没有覆盖 
    27     return 0;
    28 }
  • 相关阅读:
    GridView中使用DataFromatString
    添加文件Node
    GridView技巧1:加入序号
    Android UI控件Spinner控件的学习
    Android UI开发之RadioButton
    二叉树
    visual studio toolbox 修复
    github笔记
    nhibernate manytoone 没有匹配项时的异常
    DataMember 特性
  • 原文地址:https://www.cnblogs.com/New-ljx/p/10663090.html
Copyright © 2011-2022 走看看