HDU covers an area of 1255 square meters (rectangular area and multiple times)

Source: Internet
Author: User
Covered Area

Time Limit: 10000/5000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1949 accepted submission (s): 960


Problem description is a number of rectangles on the plane. The area of the area covered by these rectangles is obtained at least twice.


 


The first line of input data is a positive integer T (1 <= T <= 100), representing the number of test data. the first row of each test data is a positive integer N (1 <= n <= 1000), representing the number of rectangles, followed by N rows of data, each row contains four floating point numbers, it indicates the coordinates of the upper left corner and lower right corner of a rectangle on the plane. The upper and lower sides of the rectangle are parallel to the X axis, and the left and right sides are parallel to the Y axis. the coordinate ranges from 0 to 100000.

Note: This question contains a large amount of input data. We recommend that you use scanf to read data.


Output for each group of test data, calculate the area of the area covered by these rectangles at least twice. The result is retained with two decimal places.


Sample Input

251 1 4 21 3 3 72 1.5 5 4.53.5 1.25 7.5 46 3 10 730 0 1 11 0 2 12 0 3 1
 


Sample output

7.630.00
 


Authorignatius. L & Weigang Lee


Recommendignatius. L

Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1255

This is the area of the image that covers more than two times.

Analysis, but I did not expect a better method...

Code:

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#define ls rt<<1#define rs rt<<1|1#define lson l,m,ls#define rson m,r,rsusing namespace std;const int mm=2222;const int mn=mm<<2;struct seg{    double x,y1,y2;    int val;}g[mm];double len[mn],ret[mn],y[mm],L,R;int t[mn],val;void build(int n){    while(n--)ret[n]=len[n]=t[n]=0;}void updata(int l,int r,int rt){    if(L<=y[l]&&R>=y[r])t[rt]+=val;    else    {        int m=(l+r)>>1;        if(L<y[m])updata(lson);        if(R>y[m])updata(rson);    }    if(t[rt]>1)ret[rt]=len[rt]=y[r]-y[l];    else if(t[rt]>0)len[rt]=y[r]-y[l],ret[rt]=len[ls]+len[rs];    else if(l>=r)ret[rt]=len[rt]=0;    else len[rt]=len[ls]+len[rs],ret[rt]=ret[ls]+ret[rs];}bool cmp(seg a,seg b){    return a.x<b.x;}int main(){    int i,m,n,cs;    double ans;    scanf("%d",&cs);    while(cs--)    {        scanf("%d",&n);        for(i=0;i<n;++i)        {            scanf("%lf%lf%lf%lf",&g[i].x,&y[i],&g[i+n].x,&y[i+n]);            g[i].y1=y[i],g[i].y2=y[i+n],g[i].val=1;            g[i+n].y1=y[i],g[i+n].y2=y[i+n],g[i+n].val=-1;        }        sort(y,y+n+n);        sort(g,g+n+n,cmp);        for(m=i=0;i<n+n;++i)            if(y[m]<y[i])y[++m]=y[i];        build(m<<2);        for(ans=i=0;i<n+n;++i)        {            L=g[i].y1,R=g[i].y2,val=g[i].val;            updata(0,m,1);            if(g[i].x<g[i+1].x)ans+=(g[i+1].x-g[i].x)*ret[1];        }        printf("%.2lf\n",ans);    }    return 0;}

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.