/* I will wait for you*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <string>
#define make make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 100010;
const int maxm = 1010;
const int maxs = 26;
const int inf = 0x3f3f3f3f;
const int P = 1000000007;
const double error = 1e-1;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch <= 47 || ch >= 58)
f = (ch == 45 ? -1 : 1), ch = getchar();
while (ch >= 48 && ch <= 57)
x = x * 10 + ch - 48, ch = getchar();
return x * f;
}
struct point
{
double x, y;
} A, B, C, D;
point operator + (point a, point b)
{
return (point) {a.x + b.x, a.y + b.y};
}
point operator - (point a, point b)
{
return (point) {a.x - b.x, a.y - b.y};
}
point operator * (point a, double c)
{
return (point) {a.x * c, a.y * c};
}
point operator / (point a, double c)
{
return (point) {a.x / c, a.y / c};
}
double v1, v2, v3, ans = 1e9;
double Dis(point a, point b)
{
point c = a - b;
return sqrt(c.x * c.x + c.y * c.y);
}
double Cal(point a)
{
point d = (D - C) / 10000;
double l = 0, r = 10000;
while (r - l > error) {
double mid1 = l + (r - l) / 3 * 1;
double mid2 = l + (r - l) / 3 * 2;
point b1 = C + d * mid1;
point b2 = C + d * mid2;
double dis1 = Dis(a, b1) / v3 + Dis(b1, D) / v2;
double dis2 = Dis(a, b2) / v3 + Dis(b2, D) / v2;
if (dis1 >= dis2)
l = mid1;
if (dis1 < dis2)
r = mid2;
}
double mid = (l + r) / 2;
point b = C + d * mid;
return Dis(a, b) / v3 + Dis(b, D) / v2;
}
int main()
{
scanf("%lf%lf", &A.x, &A.y);
scanf("%lf%lf", &B.x, &B.y);
scanf("%lf%lf", &C.x, &C.y);
scanf("%lf%lf", &D.x, &D.y);
scanf("%lf%lf%lf", &v1, &v2, &v3);
point d = (B - A) / 10000;
for (int i = 0; i <= 10000; i++) {
point E = A + d * i;
double dis = Cal(E) + Dis(A, E) / v1;
ans = min(dis, ans);
}
printf("%.2lf\n", ans);
return 0;
}
似乎是可以三分里面套三分的.
/* I will wait for you*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <string>
#define make make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 100010;
const int maxm = 1010;
const int maxs = 26;
const int inf = 0x3f3f3f3f;
const int P = 1000000007;
const double error = 1e-5;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch <= 47 || ch >= 58)
f = (ch == 45 ? -1 : 1), ch = getchar();
while (ch >= 48 && ch <= 57)
x = x * 10 + ch - 48, ch = getchar();
return x * f;
}
struct point
{
double x, y;
} A, B, C, D;
point operator + (point a, point b)
{
return (point) {a.x + b.x, a.y + b.y};
}
point operator - (point a, point b)
{
return (point) {a.x - b.x, a.y - b.y};
}
point operator * (point a, double c)
{
return (point) {a.x * c, a.y * c};
}
point operator / (point a, double c)
{
return (point) {a.x / c, a.y / c};
}
double v1, v2, v3;
double Dis(point a, point b)
{
point c = a - b;
return sqrt(c.x * c.x + c.y * c.y);
}
double Cal2(point a)
{
point d =D - C;
double l = 0, r = 1;
while (r - l > error) {
double mid1 = l + (r - l) / 3 * 1;
double mid2 = l + (r - l) / 3 * 2;
point b1 = C + d * mid1;
point b2 = C + d * mid2;
double dis1 = Dis(a, b1) / v3 + Dis(b1, D) / v2;
double dis2 = Dis(a, b2) / v3 + Dis(b2, D) / v2;
if (dis1 >= dis2)
l = mid1;
if (dis1 < dis2)
r = mid2;
}
double mid = (l + r) / 2;
point b = C + d * mid;
return Dis(a, b) / v3 + Dis(b, D) / v2;
}
double Cal1()
{
point d = B - A;
double l = 0, r = 1;
while (r - l > error) {
double mid1 = l + (r - l) / 3 * 1;
double mid2 = l + (r - l) / 3 * 2;
point a1 = A + d * mid1;
point a2 = A + d * mid2;
double dis1 = Dis(A, a1) / v1 + Cal2(a1);
double dis2 = Dis(A, a2) / v1 + Cal2(a2);
if (dis1 >= dis2)
l = mid1;
if (dis1 < dis2)
r = mid2;
}
double mid = (l + r) / 2;
point a = A + d * mid;
return Dis(A, a) / v1 + Cal2(a);
}
int main()
{
scanf("%lf%lf", &A.x, &A.y);
scanf("%lf%lf", &B.x, &B.y);
scanf("%lf%lf", &C.x, &C.y);
scanf("%lf%lf", &D.x, &D.y);
scanf("%lf%lf%lf", &v1, &v2, &v3);
printf("%.2lf\n", Cal1());
return 0;
}

567

被折叠的 条评论
为什么被折叠?



