这道题注意矩形的交集还是矩形,所以求交集搞出一个类似于前缀和后缀和的东西,从头到位暴力,只要满足出去当前矩形的其余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; } } }
原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10257302.html
时间: 2024-10-18 04:52:32