hdu5954

我觉得这个博客属实牛逼
https://www.cnblogs.com/dilthey/p/9973558.html
通俗易懂,
连我这种高数60分的人都能看懂

其实h>=1很好考虑,,然后就要积分了。。。。。

另外!
acos他的值要特判一下!!!
我他妈前几天打比赛刚被这个傻逼东西卡自闭了。我好难啊。

#include <bits/stdc++.h>
using namespace std;
typedef long double db;
const db pi = acos(-1);
const db eps = 1e-10;
int sign(db k){
    if (k>eps) return 1; else if (k<-eps) return -1; return 0;
}
int cmp(db k1,db k2){return sign(k1-k2);}
db get(db alf){
    return pi*cos(alf)+sin(alf)-alf*cos(alf)-pow(sin(alf),3)/3.0;
}
db check(db x){
    db p = 2.0/tan(x)-1;
    if(p>1)p=1.0;
    if(p<-1)p=-1.0;
    return abs(tan(x)*(get(acos(p))-get(pi)));
}
int t;db h;
int main(){
    ios::sync_with_stdio(false);
    cout.flags(ios::fixed);
    cout.precision(5);
    cin>>t;
    while (t--){
        cin>>h;
        if(cmp(h,1)>=0){//
            db l = (2.0-h)*2;
            db a = sqrt(l*l+4);
            a/=2;
            db b = 1;
            db S = pi*a*b;
            cout<<S<<endl;
        }else if(cmp(h,0)>0){
            db l=pi/4,r=pi/2;
            while (l+0.000000001<r){
                db m = (l+r)/2;
                //db v_ = check(m);
                if(check(m)>pi*h){
                    l=m;
                }else{
                    r=m;
                }
            }
            db p = 2.0/tan(l)-1;
            if(p>1)p=1.0;
            if(p<-1)p=-1.0;
            db alf = acos(p);
            db ss = pi-alf+sin(alf*2)/2;
            cout<<ss/cos(l)<<endl;
        }else{
            cout<<0.0<<endl;
        }
    }
}
posted @ 2019-11-04 23:49  MXang  阅读(190)  评论(0编辑  收藏  举报