幾何和網路流的結合 戰火星空

2021-06-16 11:11:29 字數 2384 閱讀 2593

這題一開始折磨了我乙個上午,下狠心重編,結果一下就過了。看來重編也算是個好方法。

題目大意:在平面上有n個boss,boss始不會動,還有m架小飛機,給出每架小飛機的飛行路線(是線段,飛到終點後消失),還有射程(即乙個圓的半徑),飛行速度,能量,每攻擊boss乙個單位的時間就要消耗乙個單位的能量(攻擊的時間可以是小數),boss不能在同一時刻被多架飛機攻擊。求boss被攻擊的最大總時間。

首先要知道如何求boss被每架飛機攻擊的時間。這裡需要求直線和圓的交點(或許會有兩個,也可能沒有)。

直線方程:ax + by + c = 0:

設飛行路線線段的兩個端點的座標分別為(x1, y1),(x2, y2)。

a = y1 - y2;

b = x2 - x1;

c = x1 * y2 - x2 * y1。

圓的方程 :

設boss的座標為(p, q),射程為r

(x - p) ^ 2 + (y - q) ^ 2 = r ^ 2

一元二次方程的標準形式為 

a' x ^ 2 + b' x + c' = 0,運用公式法  x = ( - b' ± sqrt ( b' ^ 2 - 4 a' c') ) / (2 a')。

為了區分開直線方程的a和一元二次方程的a,一元二次方程的是a'(有一撇『)。

a' = 1 + (a ^ 2) / (b ^ 2);

b' = - 2 p + 2 a c / (b ^ 2) + 2 a q / b;

c' = - (r ^ 2) + p ^ 2 + q ^ 2 + (c ^ 2) / (b ^ 2) + 2 q c / b。

當b為0時(即x1 = x2)要特別判斷一下,這時候x就等於x1,y的值也好求了。

求出了交點,那麼攻擊的時間也容易求了,然後就是網路流構圖。

對於「boss不能在同一時刻被多架飛機攻擊」這個條件,正好能解決。

然後做一次小數的網路流就可以了。

#include #include #include #include #include #include #include using namespace std;

#define x first

#define y second

typedef pairpoint;

typedef point interval;

const int n = 20, m = 20;

const int fv = 2 + m + 2 * n * m;

const int fe = (m + (m + 1) * 2 * n * m) * 2;

int n, m;

point boss[n], start[m], end[m];

int v[m], r[m], e[m];

void init()

}int source = 0, sink = 1, vc = 2, ec = 0;

int from[fv], to[fe], next[fe];

double cap[fe];

void insert(int u, int v, double c)

int arrc;

pairarr[2 * n * m];

int plane_cur[m];

setplane_set;

inline double squ(double a)

inline double dis(point &a, point &b)

interval calc(point &a, point &b, int v, point p, int r)

else

if ((a < b) != (c < d)) swap(c,d);

if (a < b)

else

return make_pair(dis(a, c) / v, dis(a, d) / v);

}void graph()

for (int i = 0; i < n; i ++)

}sort(arr, arr + arrc);

for (int i = 0; i < arrc; i ++)

} }}

queueq;

int lev[fv];

bool bfs()

} }return false;

}double search(int u, double flow)

} } return flow -= rest;

}void dinic()

printf("%.6lf\n", ans);

}int main()

簡單立體幾何和DP的結合

將乙個面對映到六個面去。就例如題目給出的這個面是正面,那麼你可以使它變成背面,上面,下面等。然後進行合理性的判斷。類似於uva10051,uva437 uva10051 include using namespace std include include char wei 6 10 int pat...

網路流相關 最大流和費用流的EK演算法實現

luogu p3376 最大流是網路流模型的乙個基礎問題。網路流模型就是一種特殊的有向圖。概念 對於網路流模型 g v,e v 為點集,e 為邊集 有如下性質 最大流問題,用通俗的方式解釋就是從源點s到匯點t輸送流量,詢問最多有多少流量能輸送到匯點。對於這樣的問題,我們引入一些新概念 ford fu...

bzoj1412 狼和羊的故事 網路流

實際上就是在狼和羊之間連邊,求最小割。但是狼和羊的領地之間可能有空地,因此空地也要連。然後建立超級源點和超級匯點,跑最大流即可。ac 如下 include include include define inf 1000000000 define n 10005 define m 100005 usi...