jsoi2012-Summer Camp Mar Maps

Source: Internet
Author: User

Mars Adventure

source program Name MAR.??? (PAS,C,CPP)

Enter file name MAR. Inch

Output File name MAR. Out

time limit 1S

Problem Description:

In 2051, several Mars explorers explored different areas of the red Planet and made maps of these areas. Now, the Baltic Space Agency has an ambitious plan: they want to make a map of the whole planet. To consider the necessary work, they need to know the size of all the areas that already exist on the map. Your task is to write a program that calculates the size of the area.

Task:

L Read the description of the map shape from the input file mar.in

L Calculate all areas covered by the map

L output to output file Mar.out

Input:

The first line of the input file mar.in contains an integer N (1<=n<=10000) that represents the number of maps available.

The following n lines, each describing a map.

Each line consists of 4 integers x1,y1,x2 and y2 (0<=x1<x2<=30000,0<=y1<y2<=30 000). VALUES (x1,y1) and (x2,y2) are coordinates that represent the upper-left and lower-right coordinates of the drawing area, respectively. Each map is rectangular, and its edges are parallel to the x-axis or y-axis.

Output:

The output file, Mar.out, should contain an integer that represents the total area of the exploration area (that is, the public area of all rectangles).

Examples:

MAR. Inch

2
10 10 20 20
15 15 25 30

MAR. Out

225
  
  

See also template problem t_t. There's no way to do that.

It's just a first-time study of scan line statistics perimeter area.

Codes:

1#include <Set>2#include <queue>3#include <vector>4#include <cstdio>5#include <cstdlib>6#include <cstring>7#include <iostream>8#include <algorithm>9 using namespacestd;Ten Const intN =30010; One #defineCH1 (i<<1) A #defineCH2 (ch1|1) - #defineMid (i) T[i].mid - #defineLen (i) t[i].r-t[i].l the #definefor (i,n) for (int i=1;i<=n;i++) - #defineREP (I,L,R) for (int i=l;i<=r;i++) -  - structlines{ +     intL,r,h,kind; - }l[n]; +  A structtnode{ at     intL,r,mid; -     intCover,len; -}t[n<<2]; -  - intN,tot,x1,y1,x2,y2,lim,ans; -  in BOOLCMP (lines a,lines B) { -     returna.h<B.h; to } +  - voidBuild (intLintRinti) { theT[I].L = l; T[I].R = R; T[i].mid = (l+r) >>1; *     if(l==r-1)return; $ Build (L,mid (i), Ch1); Build (Mid (i), R,CH2);Panax Notoginseng } -  the voidModify (intLintRintDeltainti) { +     if(l<=t[i].l&&t[i].r<=R) { At[i].cover+=Delta; the         if(T[i].cover) T[i].len = Len (i);Else +         if(l==r-1) T[i].len =0;Else -T[i].len = T[ch1].len +T[ch2].len; $         return; $     } -     if(R<=mid (i)) Modify (L,R,DELTA,CH1);Else -     if(L>=mid (i)) Modify (L,R,DELTA,CH2);Else the Modify (L,mid (i), delta,ch1), Modify (Mid (i), R,DELTA,CH2); -     if(T[i].cover) T[i].len =Len (i);Wuyi     ElseT[i].len = T[ch1].len +T[ch2].len; the } -  Wu voidinit () { -scanf"%d",&n); About For (i,n) { $scanf"%d%d%d%d",&x1,&y1,&x2,&y2); -L[++TOT].L = x1; L[TOT].R = x2; l[tot].h = y1; L[tot].kind =0; -L[++TOT].L = x1; L[TOT].R = x2; L[tot].h = y2; L[tot].kind =1; -Lim =Max (lim,x2); A     } +Sort (L +1, l+tot+1, CMP); theBuild (0, Lim,1); l[0].h = l[1].h; - } $  the intMain () { theFreopen ("mar.in","R", stdin); theFreopen ("Mar.out","W", stdout); the init (); - For (I,tot) { in         if(!l[i].kind) { theans+=t[1].len* (l[i].h-l[i-1].h); theModify (L[I].L,L[I].R,1,1); About}Else{ theans+=t[1].len* (l[i].h-l[i-1].h); theModify (l[i].l,l[i].r,-1,1); the         } +     } -cout<<ans<<Endl; the     return 0;Bayi}

 
   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.