tjut 5954

来源:互联网 发布:孤岛惊魂4流畅优化 编辑:程序博客网 时间:2024/05/16 01:21
#include <bits/stdc++.h>using namespace std;double Pi = acos(-1.0);double eps = 1e-100;double tran = 180/Pi;double vd;double V(double a) {    return Pi*cos(a) - a*cos(a) + sin(a) - pow(sin(a), 3)/3;}double get(double theta) {    double a1 = acos(2*tan(theta)-1);    double v = (V(a1) - V(Pi))/tan(theta);    return v;}bool eq(double x, double y) {    return fabs(x-y) < eps;}double find(double l, double r) {    int cnt = 200;    if(eq(get(l), vd)) return l;    while(cnt--) {        double mid = (l+r) / 2;        double gd = get(mid);        if(eq(gd, vd)) return mid;        if(gd > vd) r = mid;        else l = mid;    }    return l;}int main() {    int T;    scanf("%d", &T);    while(T--) {        double d;        scanf("%lf", &d);        vd = d * Pi;        if(eq(d, 0)) {            printf("0.00000\n");            continue;        }        if(d - 1 > 0) {            double theta = atan(2.0-d);            double ans = Pi/cos(theta);        //  printf("d>1 theta = %.5f\n", theta*tran);            printf("%.5f\n", ans);            continue;        }        double theta = find(eps, Pi/4);        double a1 = acos(2 * tan(theta) - 1);        double S1 = Pi - a1 + cos(a1) * sin(a1);        double ans = S1 / sin(theta);        printf("%.5f\n", ans);    }    return 0;}

0 0
原创粉丝点击