Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
The new general manager Gill Bates has been to a seminar on time management. Ever since she has been bothering all of her staff to manage their own time. Now she plans to take it one step further: she wants to start managing her space too. And since she has
also learned to start small, she wants to start by managing her desk space. Work tends to pile up on her desk, especially since the time management training where she was taught to order all documents in neat piles and organize her work accordingly. She now
needs to calculate how much desk space is occupied. For this she comes up with a cunning plan. First, she orders her staff to measure the size and exact location of each document on the desk, in tenths of millimeters accuracy. As Gill is a very tidy person,
all her document are completely on her desk, and are all perfectly aligned to the edges of the desk (i.e. the edges of all documents are parallel to an edge of the desk). For each document, the staff writes down the position of the lower left corner of the
document and its size.
What you need to do now is to write a program that, given the input from the staff, calculates the occupied space on the desk. The maximum size of the desk is 2 * 1 meters. There is a maximum of 500 documents on the desk.
Input
The first line of the input consists of the number N of desks to be considered. Next follows for each desk the number of documents. Then follows for each document a separate line with 4 numbers: the smallest X and Y co-ordinates (i.e. the lower left corner),
and the width and height of the document respectively.
Output
The output consists of N lines containing the amount of occupied space on each desk in squared tenths of millimeters.
Sample Input
220 0 1000 10000 0 1000 10003 0 0 2 2 2 2 2 2 1 1 2 2
Sample Output
100000010
題目分析:
很經典的一個問題,可以把平面變成一個二維數組,若有覆蓋為true,若沒有覆蓋則為false,最後只要統計這個數組就可以。但是如果空間太大的話,可以採取離散化的方法,就是把一個平面分成若干個矩形,然後判斷是否覆蓋。離散化方法(http://blog.csdn.net/titikdhu/article/details/5727223)
/**/#include<iostream>#include <iomanip>#include<stdio.h>#include<cmath>#include<iomanip>#include<list>#include <map>#include <vector>#include <string>#include <algorithm>#include <sstream>#include <stack>#include<queue>#include<string.h>#include<set>using namespace std;typedef struct REC{int left;int low;int width;int height;}Rec;bool a[2001][1001];int main(){int n;cin>>n;for(int xx=0;xx<n;xx++){memset(a,0,sizeof(a));int num;cin>>num;vector<Rec> data(num);for(int i=0;i<num;i++){cin>>data[i].left>>data[i].low>>data[i].width>>data[i].height;for(int w=0;w<data[i].width;w++){for(int ww=0;ww<data[i].height;ww++)a[w+data[i].left][ww+data[i].low]=true;}}unsigned long long sum=0;for(int i=0;i<2001;i++){for(int j=0;j<1001;j++){if(a[i][j])sum++;}}cout<<sum<<endl;}//end for}