1. 程式人生 > >codeforces AIM Tec round 5(div1+div2) C. Rectangles

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\n",now.x1,now.y1); break; } } }