日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces 1028C(面积并/思维)

發布時間:2024/4/17 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces 1028C(面积并/思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門

題面:

C. Rectangles

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given?nn?rectangles on a plane with coordinates of their bottom left and upper right points. Some?(n?1)(n?1)?of the given?nn?rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.

Find any point with integer coordinates that belongs to at least?(n?1)(n?1)?given rectangles.

Input

The first line contains a single integer?nn?(2≤n≤1326742≤n≤132674) — the number of given rectangles.

Each the next?nn?lines contains four integers?x1x1,?y1y1,?x2x2?and?y2y2?(?109≤x1<x2≤109?109≤x1<x2≤109,??109≤y1<y2≤109?109≤y1<y2≤109) — the coordinates of the bottom left and upper right corners of a rectangle.

Output

Print two integers?xx?and?yy?— the coordinates of any point that belongs to at least?(n?1)(n?1)?given rectangles.

Examples

input

Copy

3 0 0 1 1 1 1 2 2 3 0 4 1

output

Copy

1 1

input

Copy

3 0 0 1 1 0 1 1 2 1 0 2 1

output

Copy

1 1

input

Copy

4 0 0 5 5 0 0 4 4 1 1 4 4 1 1 4 4

output

Copy

1 1

input

Copy

5 0 0 10 8 1 2 6 7 2 3 5 6 3 4 4 5 8 1 9 2

output

Copy

3 4

Note

The picture below shows the rectangles in the first and second samples. The possible answers are highlighted.

The picture below shows the rectangles in the third and fourth samples.

題意:

? ? 給你n個矩陣的左下角的點和右上角的點,讓你求出一點使得這個點包含最少n-1個矩陣。(題目數據保證一定有解)。

題目分析:

? ? 因為題目中要求我們求出一個包含n-1個矩陣的點,因此我們不難想到這個點一定是在這n個矩形的面積并中。因此我們考慮從面積并入手解決問題。

? ? 考慮我們優先對矩形進行正向遍歷,在遍歷過程中不斷維護前綴面積并pre,此時我們可以發現,正向遍歷后的結果必為存在一個至少包含n-1個面積并矩形或者不存在矩形。而根據題意必定有解,則此時,倘若我們反向遍歷,在遍歷過程中維護后綴面積并suf,則此時遍歷后的結果必定有一個面積并矩形。而我們的答案則必定是在正反遍歷后得到的面積并矩陣之中。

? ? 因此我們只需要枚舉前綴面積并pre和后綴面積并suf,并在最后判斷得到的每一個面積并矩形是否能構成矩形即可。

代碼:

#include <bits/stdc++.h> #define maxn 150000 using namespace std; const int INF=0x3f3f3f3f; struct node{int lx,ly,rx,ry;node(){}node(int _lx,int _ly,int _rx,int _ry){lx=_lx,ly=_ly,rx=_rx,ry=_ry;} }q[maxn],pre[maxn],suf[maxn]; bool judge(node a){if(a.lx>a.rx||a.ly>a.ry) return false;return true; } int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d%d%d%d",&q[i].lx,&q[i].ly,&q[i].rx,&q[i].ry);}pre[0].lx=pre[0].ly=-INF;pre[0].rx=pre[0].ry=INF;for(int i=1;i<=n;i++){//維護前綴面積并pre[i].lx=max(pre[i-1].lx,q[i].lx);pre[i].ly=max(pre[i-1].ly,q[i].ly);pre[i].rx=min(pre[i-1].rx,q[i].rx);pre[i].ry=min(pre[i-1].ry,q[i].ry);}suf[n+1].lx=suf[n+1].ly=-INF;suf[n+1].rx=suf[n+1].ry=INF;for(int i=n;i>=1;i--){//維護后綴面積并suf[i].lx=max(suf[i+1].lx,q[i].lx);suf[i].ly=max(suf[i+1].ly,q[i].ly);suf[i].rx=min(suf[i+1].rx,q[i].rx);suf[i].ry=min(suf[i+1].ry,q[i].ry);}for(int i=1;i<=n;i++){int tmplx=max(pre[i-1].lx,suf[i+1].lx);int tmply=max(pre[i-1].ly,suf[i+1].ly);int tmprx=min(pre[i-1].rx,suf[i+1].rx);int tmpry=min(pre[i-1].ry,suf[i+1].ry);if(judge(node(tmplx,tmply,tmprx,tmpry))){//判斷是否能構成矩形cout<<tmplx<<" "<<tmply<<endl;return 0;}}return 0; }

?

轉載于:https://www.cnblogs.com/Chen-Jr/p/11007216.html

總結

以上是生活随笔為你收集整理的Codeforces 1028C(面积并/思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。