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

Posted lishengkangshidatiancai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces AIM Tec round 5(div1+div2) C. Rectangles相关的知识,希望对你有一定的参考价值。

这道题注意矩形的交集还是矩形,所以求交集搞出一个类似于前缀和后缀和的东西,从头到位暴力,只要满足出去当前矩形的其余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
",now.x1,now.y1);
            break;
        }
    }
}

 

以上是关于codeforces AIM Tec round 5(div1+div2) C. Rectangles的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces_AIM Tech Round 3 (Div. 1)_A

Codeforces_AIM Tech Round 3 (Div. 1)_B

Codeforces Aim Tech Round4 (Div2) D

codeforces708b// Recover the String //AIM Tech Round 3 (Div. 1)

AIM Tech Round 5 1028cf(A-E)

AIM Tech Round 5C. Rectangles 思维