POJ 3565 Ants(計算幾何,KM)

2021-06-08 17:06:42 字數 1092 閱讀 3242

by---cxlove

題目:給出一些螞蟻的點,給出一些樹的點,兩兩對應,使他們的連線不相交,輸出一種方案。

可以任意假定一種組合,然後兩兩判斷,如果相交,則交換,直到全部不相交為止。

這種思想很新穎,被稱為計算幾何中的調整思想。

#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long long

#define eps 1e-8

#define inf 10000

#define zero(a) fabs(a)=min(s2a.x,s2b.x)&&max(s2a.x,s2b.x)>=min(s1a.x,s1b.x)

&&max(s1a.y,s1b.y)>=min(s2a.y,s2b.y)&&max(s2a.y,s2b.y)>=min(s1a.y,s1b.y))

if(xmul(s1a,s1b,s2a)*xmul(s1a,s1b,s2b)<-eps)

if(xmul(s2a,s2b,s1a)*xmul(s2a,s2b,s1b)<-eps)

return true;

return false;

}int main(){

int n;

while(scanf("%d",&n)!=eof){

for(int i=0;i

其中的原因便是,最小權的匹配肯定是不相交的。

如果ab與cd相交於e,那麼ac

但是我寫的不知道為什麼tle,km不熟,也許有問題,至少可以這麼做,一般在200ms以內

#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long long

#define eps 1e-5

#define inf 1ll<<50

#define zero(a) fabs(a)

POJ 3565 Ants 最小權匹配

53題意 白點,黑點各有n個,每對黑白點之間連乙個線段,問在保證線段不相交的情況下,應該怎麼連,使其距離和最小 距離為歐幾里德距離 輸出每個白點所對應的黑點編號。思路 很明顯是二分圖最小權值匹配問題,由於km演算法求的是最大權值匹配,故要將權值取負,然後用 km 模板即可,最後結果再取反輸出 對於k...

poj1696 計算幾何

運用叉積判斷是否是逆時針,因為同一直線上也行,所以有n個植物就可以吃掉n個植物 include include include include include define dist a,b sqrt 1.0 a.x b.x a.x b.x 1.0 a.y b.y a.y b.y define cr...

poj1106 計算幾何

求在可以旋轉的給定圓心和半徑的半圓中最多點的個數 include include include include include define dist a,b sqrt 1.0 a.x b.x a.x b.x 1.0 a.y b.y a.y b.y define cross a,b,c 1.0 b...