三分
雨巨点名的三分题……本菜鸡还是不太懂,观摩其他大佬的代码终于有点理解。
我们先三分出从A点到AB中的某个点X,作为出发点,然后,再三分出从X到CD的某个点Y,再从Y直接到D,这样,我们就可以求出最小的值了。
路径的话,存在4条路,分别代表走不走传送带。
不走AB带就直接走到B,不走CD带就直接从x走到D,直接码三分的板子就行了,向量求起来有点复杂,要仔细。
精度问题,建议double的直接循环100或者1000次,看题目规模去改,别搞超时了。
#pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math") #include <bits/stdc++.h> using namespace std; #define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define all(vv) (vv).begin(), (vv).end() #define endl "\n" typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll MOD = 1e9 + 7; inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; } inline void write(ll x) { if (!x) { putchar('0'); return; } char F[40]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0; while (tmp > 0) { F[cnt++] = tmp % 10 + '0'; tmp /= 10; } while (cnt > 0)putchar(F[--cnt]); } inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; } inline int lowbit(int x) { return x & (-x); } const double eps = 1e-4; double p, q, r; struct node { double x, y; }a, b, c, d, e, f; double dis(node a, node b) { return sqrt(eps + (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double check1(double x) { f = { c.x + (x / dis(c,d) * (d.x - c.x)),c.y + (x / dis(c,d) * (d.y - c.y)) }; return dis(e, f) / r + (dis(c, d) - x) / q; } double check(double x) { e = { a.x + x / dis(a,b) * (b.x - a.x),a.y + x / dis(a,b) * (b.y - a.y) }; double l = 0, r = dis(c, d); for (int i = 1; i <= 1000; i++) { double lm = l + (r - l) / 3, rm = r - (r - l) / 3; if (check1(lm) >= check1(rm))l = lm; else r = rm; } return check1(l) + x / p; } int main() { cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y; cin >> p >> q >> r; double l = 0, r = dis(a, b); for (int i = 1; i <= 1000; i++) { double lm = l + (r - l) / 3, rm = r - (r - l) / 3; if (check(lm) >= check(rm))l = lm; else r = rm; } printf("%.2f", check(l)); return 0; }