[BZOJ1857][Scoi2010]传送带
生活随笔
收集整理的這篇文章主要介紹了
[BZOJ1857][Scoi2010]传送带
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1857: [Scoi2010]傳送帶
Time Limit: 1 Sec??Memory Limit: 64 MB Submit: 1786??Solved: 981 [Submit][Status][Discuss]Description
在一個(gè)2維平面上有兩條傳送帶,每一條傳送帶可以看成是一條線段。兩條傳送帶分別為線段AB和線段CD。lxhgww在AB上的移動(dòng)速度為P,在CD上的移動(dòng)速度為Q,在平面上的移動(dòng)速度R。現(xiàn)在lxhgww想從A點(diǎn)走到D點(diǎn),他想知道最少需要走多長(zhǎng)時(shí)間Input
輸入數(shù)據(jù)第一行是4個(gè)整數(shù),表示A和B的坐標(biāo),分別為Ax,Ay,Bx,By 第二行是4個(gè)整數(shù),表示C和D的坐標(biāo),分別為Cx,Cy,Dx,Dy 第三行是3個(gè)整數(shù),分別是P,Q,ROutput
輸出數(shù)據(jù)為一行,表示lxhgww從A點(diǎn)走到D點(diǎn)的最短時(shí)間,保留到小數(shù)點(diǎn)后2位Sample Input
0 0 0 100100 0 100 100
2 2 1
Sample Output
136.60HINT
對(duì)于100%的數(shù)據(jù),1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000 ???????????????? 1<=P,Q,R<=10
?
路徑顯然是先在第一條線段上走一段,然后在平面上走一段,再到第二條線段上走一段
根據(jù)生活經(jīng)驗(yàn)
如果把點(diǎn)的位置看作自變量,距離看作函數(shù)值,那么肯定有一點(diǎn)最優(yōu)然后兩邊單調(diào)地變劣
所以可以在第一根線段上三分,然后求最短距離則需要在第二根線段上三分
#include <cmath> #include <cstdio> #include <iostream> using namespace std; double xl1, yl1, xr1, yr1, xl2, yl2, xr2, yr2, len1, len2, xx, yy, p, q, r; inline double sqr(const double &x){return x * x; } inline double dis(const double &x1, const double &y1, const double &x2, const double &y2){return sqr(x1 - x2) + sqr(y1 - y2); } inline double calc2(const double &lam){double xt = xl2 + lam * (xr2 - xl2), yt = yl2 + lam * (yr2 - yl2);return sqrt(dis(xx, yy, xt, yt)) / r + len2 * (1 - lam) / q; } inline double calc(const double &lam){xx = xl1 + lam * (xr1 - xl1), yy = yl1 + lam * (yr1 - yl1);double l = 0, r = 1, m1, m2, t1, t2;while(r - l > 0.00001){m1 = (r + 2 * l) / 3;m2 = (2 * r + l) / 3;t1 = calc2(m1);t2 = calc2(m2);if(t1 > t2) l = m1;else r = m2;}return len1 * lam / p + min(t1, t2); } int main(){cin >> xl1 >> yl1 >> xr1 >> yr1 >> xl2 >> yl2 >> xr2 >> yr2 >> p >> q >> r;len1 = sqrt(dis(xl1, yl1, xr1, yr1));len2 = sqrt(dis(xl2, yl2, xr2, yr2));double l = 0, r = 1, m1, m2, t1, t2;while(r - l > 0.00001){m1 = (r + 2 * l) / 3;m2 = (2 * r + l) / 3;t1 = calc(m1);t2 = calc(m2);if(t1 > t2) l = m1;else r = m2;}printf("%.2lf", min(t1, t2));return 0; }
?
轉(zhuǎn)載于:https://www.cnblogs.com/ruoruoruo/p/7768677.html
總結(jié)
以上是生活随笔為你收集整理的[BZOJ1857][Scoi2010]传送带的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 微波炉烤披萨没烤盘怎么办?
- 下一篇: android使用webview时按后退