[sicily online]1045. Space Management

來源:互聯網
上載者:User
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}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.