码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces AIM Tec round 5(div1+div2) C. Rectangles

时间:2019-01-11 21:19:46      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:后缀   main   include   暴力   bit   bre   space   ace   nbsp   

这道题注意矩形的交集还是矩形,所以求交集搞出一个类似于前缀和后缀和的东西,从头到位暴力,只要满足出去当前矩形的其余n-1个的交集满足左下角小于等于右下角就可以啦

#include<bits/stdc++.h>
using namespace std;
struct rectangle{
    int x1,y1,x2,y2;
    rectangle operator + (const rectangle &rec)
    {
        rectangle newrec;
        newrec.x1=max(x1,rec.x1);
        newrec.y1=max(y1,rec.y1);
        newrec.x2=min(x2,rec.x2);
        newrec.y2=min(y2,rec.y2);
        return newrec;
    }
}pre[200000],suf[200000],rec[200000];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        rec[i].x1=x1;
        rec[i].x2=x2;
        rec[i].y1=y1;
        rec[i].y2=y2;
    }
    pre[1]=rec[1];
    for(int i=2;i<=n;i++)
    {
        pre[i]=rec[i]+pre[i-1];
    }
    suf[n]=rec[n];
    for(int i=n-1;i>=1;i--)
    {
        suf[i]=rec[i]+suf[i+1];
    }
    for(int i=1;i<=n;i++)
    {
        rectangle now;
        if(i==1)
        {
           now=suf[2];
        }
        else if(i==n)
        {
            now=pre[n-1];
        }
        else
        {
            now=pre[i-1]+suf[i+1];
        }
        if(now.x1<=now.x2&&now.y1<=now.y2)
        {
            printf("%d %d\n",now.x1,now.y1);
            break;
        }
    }
}

 

codeforces AIM Tec round 5(div1+div2) C. Rectangles

标签:后缀   main   include   暴力   bit   bre   space   ace   nbsp   

原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10257302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!