Display materials

Background to the issue:
the outbreak of epidemic pneumonia in Wuhan novel coronavirus infection affects the hearts of people all over the country, a difficult one, P Plus support. Up to now, Shandong Shouguang Vegetable donated to Wuhan has reached 1120 tons; Russia and China General Chamber of Commerce organized the donation of various types of protective equipment at Russian enterprises, overseas Chinese about 15 tons; helicopter airborne Xinhua Road Stadium, Union Hospital of Wuhan solution ...... urgent needs of a large number of donations storage management is a big problem. If not handled properly is not that a waste of resources, but also cold heart majority of caring people.
Description of the problem:
There are a square of an empty space used to store supplies of n, one field is divided into small regions in square 1. A total of m batch of materials need to be stored, numbered 1-m, according to the staff numbers in the order stored m this batch materials, each batch of goods need to select a rectangular area storage. If the selected rectangular area, the area has a small square supplies, then this batch of material to the top of the stack of small square area. Your task is to query the top of a small square area of materials belonging to several groups, without supplies output 0.
Note: This time limit title 1s, 256MB of space limitations (here are explained with the rearmost tips)
plan view:

Input Description:
Line 1 two integers n and m
Subsequently m rows of four integers x1, y1, x2, y2, respectively, these supplies the selected upper left corner of the rectangular region is the first row y1 x1 column, x2 y2 of the lower right corner is row column
next row 1 two integers x and y, the small square represents a region to be queried first column y x row
output description:
an integer

Sample input:
10. 5
. 1. 1. 3. 3
. 4. 6. 8. 3
. 8 10. 9 10
. 4. 5. 4. 5
2. 4. 7. 4
. 5. 4

Sample output:
5

Data range:
range of a: 1 <= n, m, x1, y1, x2, y2 <= 1000
range two: 1 <= n, m, x1, y1, x2, y2 <= 1000000

Explanation and tips:
First, the time limit 1s: 1s can be considered a rough contest 100 million to support operations.
1, for (i = 1; i <= 10; ++ i) a ++; The code may be considered to be roughly 10 times the operation
2, for (I =. 1; I <= 1000000; I ++)
for (J . 1 =; J <= 10000000; J ++)
a [I] [J] ++; the code may be considered to be roughly 1 trillion calculations
two, space limitations 256MB: here only a rough calculation of the array size. An int variable is 4B, then a 1000 1000 a two-dimensional array of occupied space: 1000 1000 4/1024/1024 = 3.81MB. 1 1000000 1000000 two-dimensional array footprint: 3814697.27MB

Ideas: Originally want to read two-dimensional array, but found space seem big, to switch to more one-dimensional arrays
   because the query uppermost material, so the query from the last time forward, found the first one to include this
   materials for the location of the top of the material in this position.
   
Code:

#include<stdio.h>
int main()
{
    int a[100],b[100],c[100],d[100];
    int n,m,x,y,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++)
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
    scanf("%d %d",&x,&y);
    for(i=m;i>=1;i--)
    {
        if(x>=a[i]&&x<=c[i]&&y>=b[i]&&y<=d[i])
            break;
    }
    printf("%d",i);
    return 0;
}

operation result:
Here Insert Picture Description

Published 10 original articles · won praise 0 · Views 180

Guess you like

Origin blog.csdn.net/koaci/article/details/104225402