[SCOI2010]传送带

在两个传送带上分别三分两个点计算 三分套三分

# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
# define Sqr(x) ((x) * (x))
using namespace std;
typedef long long ll;
const double EPS(1e-6), Div(0.382);

IL ll Read(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

double ax, ay, bx, by, cx, cy, dx, dy, p, q, r;

IL double Dis(RG double x1, RG double y1, RG double x2, RG double y2){
    RG double t1 = sqrt(Sqr(ax - x1) + Sqr(ay - y1)) / p;
    RG double t2 = sqrt(Sqr(x1 - x2) + Sqr(y1 - y2)) / r;
    RG double t3 = sqrt(Sqr(x2 - dx) + Sqr(y2 - dy)) / q;
    return t1 + t2 + t3;
}

IL double Calc(RG double x, RG double y){
    RG double x1 = cx, y1 = cy, x2 = dx, y2 = dy;
    while(fabs(x2 - x1) > EPS || fabs(y2 - y1) > EPS){
        RG double D1 = (x2 - x1) * Div, xmidl = x1 + D1, xmidr = x2 - D1;
        RG double D2 = (y2 - y1) * Div, ymidl = y1 + D2, ymidr = y2 - D2;
        RG double t1 = Dis(x, y, xmidl, ymidl), t2 = Dis(x, y, xmidr, ymidr);
        if(t1 < t2) x2 = xmidr, y2 = ymidr;
        else x1 = xmidl, y1 = ymidl;
    }
    return Dis(x, y, x1, y1);
}

int main(RG int argc, RG char* argv[]){
    ax = Read(); ay = Read(); bx = Read(); by = Read();
    cx = Read(); cy = Read(); dx = Read(); dy = Read();
    p = Read(); q = Read(); r = Read();
    RG double x1 = ax, y1 = ay, x2 = bx, y2 = by;
    while(fabs(x2 - x1) > EPS || fabs(y2 - y1) > EPS){
        RG double D1 = (x2 - x1) * Div, xmidl = x1 + D1, xmidr = x2 - D1;
        RG double D2 = (y2 - y1) * Div, ymidl = y1 + D2, ymidr = y2 - D2;
        RG double t1 = Calc(xmidl, ymidl), t2 = Calc(xmidr, ymidr);
        if(t1 < t2) x2 = xmidr, y2 = ymidr;
        else x1 = xmidl, y1 = ymidl;
    }
    printf("%.2lf\n", Calc(x1, y1));
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值