牛吃草 数论
4243: 牛吃草
Time Limit:?1 Sec??Memory Limit:?128 MBSubmit:?306??Solved:?87
Description
農(nóng)夫有一個長滿草的(x0, y0)為圓心,r為半徑的圓形牛欄,他要將一頭牛栓在坐標(biāo)(x1, y1)欄樁上,但只讓牛吃到一半草,問栓牛鼻的繩子應(yīng)為多長?
Input
輸入一個T,表示T組測試數(shù)據(jù)
下面T行每行五個整數(shù) x0, y0, x1, y1, r 所有數(shù)據(jù)的絕對值小于1e5
Output
每組測試數(shù)據(jù)輸出繩子長度,保留4位小數(shù)
Sample Input
2 0 0 0 0 2 0 0 10 10 2Sample Output
1.414214.1892
#include<cmath> #include<iostream> #include<cstring> #include<cstdio> using namespace std; const double eps=1e-8; const double pi=acos(-1.0); int dsgn(double x){ return x<-eps?-1:x>eps; } double Area(double r,double R,double l){ if(dsgn(l-r-R)>=0) return 0; else if(dsgn(l-fabs(r-R))<=0){ if(r>R) r=R; return pi*r*r; } double a=acos((l*l+r*r-R*R)/(2*l*r)); double b=acos((l*l+R*R-r*r)/(2*l*R)); double s1=a*r*r,s2=b*R*R; double S1=r*r*sin(a)*cos(a),S2=R*R*sin(b)*cos(b); return s1+s2-S1-S2; } int main(){ int t; cin>>t; while(t--) {double x0,x1,y0,y1,r;scanf("%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&r);x1-=x0,y1-=y0;double l=sqrt(x1*x1+y1*y1);double lt=0,rt=1e5;while(dsgn(rt-lt)>0){double mid=(rt+lt)/2.0;if(dsgn(2.0*Area(r,mid,l)-pi*r*r)>=0)rt=mid;elselt=mid;}printf("%.4lf\n",rt); } return 0; }
總結(jié)
- 上一篇: 数据结构实验之查找五:平方之哈希表
- 下一篇: sdut 青蛙过河