码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1857 传送带 | 三分套三分

时间:2017-12-04 20:39:53      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:using   ble   ++   速度   markdown   class   type   long   ret   

我我我我看错题了
把速度看成单位路程的时间了
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;
}

BZOJ 1857 传送带 | 三分套三分

标签:using   ble   ++   速度   markdown   class   type   long   ret   

原文地址:http://www.cnblogs.com/RabbitHu/p/BZOJ1857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!