題目鏈接:點擊查看
題目大意:二維平面坐標系上給出 nnn 個點,現在需要求出四個點,滿足四個點可以組成可退化的平行四邊形
題目分析:因為坐標的范圍很小,所以瞬間想到了上周刷到的一道題目的模型:
CodeForces - 1501C
然后就在糾結平行四邊形邊長長度的路上走遠了
賽后一看題解恍然大悟,只要去尋找兩對點 (a,b),(c,d)(a,b),(c,d)(a,b),(c,d) 滿足中點是同一個點就可以了
妙啊
因為鴿巢原理,二維平面坐標系上最多有 4e64e64e6 個點,所以每 4e64e64e6 個點對,至少會有兩個點對滿足中點相等
同時又因為結論,假如有四組點對,滿足中點相同,那么一定是可以構造出 (a,b),(c,d)(a,b),(c,d)(a,b),(c,d) 四個點互不相同的答案
所以時間復雜度就是 O(min(n2,4?4e6))O(min(n^2,4*4e6))O(min(n2,4?4e6))
代碼:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
#define lowbit(x) x&-x
using namespace std
;
typedef long long LL
;
typedef unsigned long long ull
;
template<typename T>
inline void read(T
&x
)
{T f
=1;x
=0;char ch
=getchar();while(0==isdigit(ch
)){if(ch
=='-')f
=-1;ch
=getchar();}while(0!=isdigit(ch
)) x
=(x
<<1)+(x
<<3)+ch
-'0',ch
=getchar();x
*=f
;
}
template<typename T>
inline void write(T x
)
{if(x
<0){x
=~(x
-1);putchar('-');}if(x
>9)write(x
/10);putchar(x
%10+'0');
}
const int inf
=0x3f3f3f3f;
const int N
=1e6+100;
int x
[N
],y
[N
];
struct Node {int x
,y
;Node() {}Node(int x
,int y
):x(x
),y(y
) {}bool operator!=(const Node
& t
) {return x
!=t
.x
&&x
!=t
.y
&&y
!=t
.x
&&y
!=t
.y
;}bool operator<(const Node
& t
) const {if(x
!=t
.x
) {return x
<t
.x
;}return y
<t
.y
;}
};
map
<pair
<int,int>,Node
>mp
;
int main()
{
#ifndef ONLINE_JUDGE
#endif
int n
;read(n
);for(int i
=1;i
<=n
;i
++) {read(x
[i
]),read(y
[i
]);}for(int i
=1;i
<=n
;i
++) {for(int j
=i
+1;j
<=n
;j
++) {int xx
=x
[i
]+x
[j
];int yy
=y
[i
]+y
[j
];if(!mp
.count({xx
,yy
})) {mp
[{xx
,yy
}]=Node(i
,j
);} else if(mp
[{xx
,yy
}]!=Node(i
,j
)) {puts("YES");cout
<<i
<<' '<<j
<<' '<<mp
[{xx
,yy
}].x
<<' '<<mp
[{xx
,yy
}].y
<<endl
;return 0;}}}puts("NO");return 0;
}
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生
總結
以上是生活随笔為你收集整理的兰州大学第一届『飞马杯』程序设计竞赛 - ★★平形四边行★★(鸽巢原理+暴力)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。