hdu-6514 monitor

Monitor

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 163840/163840 K (Java/Others)
Total Submission(s): 1906    Accepted Submission(s): 554


Problem Description
Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×m

But recently Xiaoteng found that his crops were often stolen by a group of people, so he decided to install some monitors to find all the people and then negotiate with them.

However, Xiao Teng bought bad monitors, each monitor can only monitor the crops inside a rectangle. There are p monitors installed by Xiaoteng, and the rectangle monitored by each monitor is known. 

Xiao Teng guess that the thieves would also steal q times of crops. he also guessed the range they were going to steal, which was also a rectangle. Xiao Teng wants to know if his monitors can see all the thieves at a time.
 
Input
There are mutiple test cases.

Each case starts with a line containing two integers n,m(1n,1m,n×m107) which represent the area of the land.

And the secend line contain a integer p(1p106) which represent the number of the monitor Xiaoteng has installed. This is followed by p lines each describing a rectangle. Each of these lines contains four intergers x1,y1,x2 and y2(1x1x2n,1y1y2m) ,meaning the lower left corner and upper right corner of the rectangle.

Next line contain a integer q(1q106) which represent the number of times that thieves will steal the crops.This is followed by q lines each describing a rectangle. Each of these lines contains four intergers x1,y1,x2 and y2(1x1x2n,1y1y2m),meaning the lower left corner and upper right corner of the rectangle.
 
Output
For each case you should print q lines.

Each line containing YES or NO mean the all thieves whether can be seen.
 
Sample Input
6 6 3 2 2 4 4 3 3 5 6 5 1 6 2 2 3 2 5 4 1 5 6 5
 
Sample Output
YES NO
Hint
In the picture,the red solid rectangles mean the monitor Xiaoteng installed, and the blue dotted rectangles mean the area will be stolen.
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6554 6553 6552 6551 6550 
 大概就是标记一下监控覆盖的范围 前缀和 要与盗贼的活动坐标围成的面积一样。
开二维数组爆内存MLE,要么用一维数组,要么用变长数组emmm学到了orz。因为它前缀和是面积所以只需要为1或0 就可以了,期间有没有被监控覆盖到的地方说明NO。
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 #include <iomanip>
15  #include <fstream>
16 using namespace std;
17 
18 int main()
19 {
20 
21     int n,m,p,q,x1,y1,x2,y2;
22     while(scanf("%d%d",&n,&m)!=EOF)
23 {
24     vector< vector<int> > a(n+2,vector<int>(m+2,0));
25 //    vector< vector<int> > pre(n+2,vector<int>(m+2,0));
26     scanf("%d",&p);
27     while(p--)
28     {
29         scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
30         a[x1][y1]++;a[x2+1][y2+1]++;
31         a[x1][y2+1]--;a[x2+1][y1]--;
32     }
33     
34     for(int i=1;i<=n;i++)
35          for(int j=1;j<=m;j++)
36         {
37             a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
38         }
39   
40     for(int i=1;i<=n;i++)
41          for(int j=1;j<=m;j++)
42         {
43         //    pre[i][j]+=pre[i-1][j]+pre[i][j-1]-pre[i][j-1]+(a[i][j]>1?1:0);
44             if(a[i][j]>1)
45                 a[i][j]=1;
46             a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
47         }
48         
49         
50     scanf("%d",&q);
51     while(q--)
52     {
53         scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
54         int s;
55         s=(x2-x1+1)*(y2-y1+1);
56         if(s==(a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]))
57             printf("YES
");
58         else 
59             printf("NO
");
60     
61     }
62 }    
63     
64     return 0;
65 }
View Code
原文地址:https://www.cnblogs.com/greenaway07/p/11190650.html