[hdu] 6097 "优秀的黄金分割三分"

题解写了这句话,比赛时写了三分。T 到飞起。赛后发现三分写丑了。然后,还是需要快速读入。果然我还是菜呀、

#include"bits/stdc++.h"
using namespace std;
const double Pi = acos(-1.0);
double x1, y1, x2, y2;
double rr;
typedef long long LL;
struct FastIO
{
    static const int S = 2 * 100;
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar()
    {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len) exit(0);
        return buf[pos ++];
    }
    inline int xuint()
    {
        int c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x;
    }
    inline int xint()
    {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline void xstring(char *s)
    {
        int c = xchar();
        while (c <= 32) c = xchar();
        for (; c > 32; c = xchar()) * s++ = c;
        *s = 0;
    }
    inline void wchar(int x)
    {
        if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos ++] = x;
    }
    inline void wint(LL x)
    {
        if (x < 0) wchar('-'), x = -x;
        char s[24];
        int n = 0;
        while (x || !n) s[n ++] = '0' + x % 10, x /= 10;
        while (n--) wchar(s[n]);
    }
    inline void wstring(const char *s)
    {
        while (*s) wchar(*s++);
    }
    ~FastIO()
    {
        if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;
double get_lens(double arg1)
{
    double x11 = rr * cos(arg1);
    double y12 = rr * sin(arg1);
    return sqrt((x11 - x1) * (x11 - x1) + (y12 - y1) * (y12 - y1)) + sqrt((x11 - x2) * (x11 - x2) + (y12 - y2) * (y12 - y2));
}
int main()
{
    //freopen("data.in", "r", stdin);
    //freopen("data1.out", "w", stdout);
    int T;
    double d = (sqrt(5) - 1) / 2;
    T = io.xint();
    while(T --){
        rr = io.xint();
        x1 = io.xint(); y1 = io.xint();
        x2 = io.xint(); y2 = io.xint();
        double t = x1 * x1 + y1 * y1;
        double a = atan2(y1, x1);
        double b = atan2(y2, x2);
        if(a < 0) a += 2 * Pi;
        if(b < 0) b += 2 * Pi;
        double l, r;
        if(a > b){
            r = a; l = b;
        }
        else{
            r = b; l = a;
        }
        if(r - l > Pi){
            r -= 2 * Pi;
            swap(l , r);
        }
        r = (l + r) / 2.0;
        double midl = (l * d + r * (1 - d));
        double midr = (l * (1 - d) + r * d);
        double lans = get_lens(midl);
        double rans = get_lens(midr);
        for(int i = 1; i <= 30; i ++){
            if(lans < rans){
                r = midr;
                midr = midl;
                midl = l * d + r * (1 - d);
                rans = lans;
                lans = get_lens(midl);
            }
            else{
                l = midl;
                midl = midr;
                midr = l * (1 - d) + r * d;
                lans = rans;
                rans = get_lens(midr);
            }
        }
        printf("%.12f\n", get_lens(l));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值