BZOJ 1857 传送带 | 三分套三分
我我我我看错题了
把速度看成单位路程的时间了
GG
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;
typedef long long ll;
template <class T>
void read(T &x){
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}
const int N = 100005;
struct point {
double x, y;
point operator - (point b){
return (point){x - b.x, y - b.y};
}
point operator * (double b){
return (point){x * b, y * b};
}
point operator + (point b){
return (point){x + b.x, y + b.y};
}
double norm(){
return sqrt(x * x + y * y);
}
} A, B, C, D;
double P, Q, R;
double calc(double a, double b){
point X = (B - A) * a, Y = (C - D) * b;
double res = X.norm() / P + Y.norm() / Q + (D + Y - A - X).norm() / R;
return res;
}
double tri(double mid){
double l = 0, r = 1;
int cnt = 0;
while(cnt < 500){
++cnt;
double dlt = (r - l) / 3, m1 = l + dlt, m2 = r - dlt;
double res1 = calc(mid, m1), res2 = calc(mid, m2);
if(res1 > res2) l = m1;
else r = m2;
}
return calc(mid, l);
}
int main(){
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &D.x, &D.y)){
scanf("%lf%lf%lf", &P, &Q, &R);
double l = 0, r = 1;
int cnt = 0;
while(cnt < 500){
++cnt;
double dlt = (r - l) / 3, m1 = l + dlt, m2 = r - dlt;
double res1 = tri(m1), res2 = tri(m2);
if(res1 > res2) l = m1;
else r = m2;
}
printf("%.2lf\n", tri(l));
}
return 0;
}
本文作者:胡小兔
博客地址:http://rabbithu.cnblogs.com
博客地址:http://rabbithu.cnblogs.com