soj 1698 Hungry Cow_三角函数
题意:有只牛要吃草,现在有个墙挡着,给你绑着牛的绳的长度,墙的长度,绳原点到墙的距离,问牛能在多大的面积里吃草
思路:分为四种情况,详情请看书。被dp卡着这题没做成
1 #include <iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 #define eps 1e-8 7 const double PI=acos(-1.0); 8 double l,d,s; 9 double solve(){ 10 11 if(s-d<eps)//1 12 return PI*s*s; 13 double dist=sqrt(0.25*l*l+d*d),ans=0; 14 if(s-dist<eps){//2 15 double angle=acos(d/s); 16 ans=(PI-angle)*s*s+s*d*sin(angle); 17 18 }else{//3,4 19 double angle=asin(0.5*l/dist); 20 ans+=(PI-angle)*s*s+0.5*l*d; 21 s-=dist; 22 angle+=0.5*PI; 23 ans+=angle*s*s; 24 if(s+s-l>eps){ 25 double angle1=acos(0.5*l/s); 26 ans-=angle1*s*s-0.5*sin(angle1)*s*l; 27 } 28 29 } 30 return ans; 31 } 32 int main(int argc, char** argv) { 33 int t; 34 double ans; 35 scanf("%d",&t); 36 while(t--){ 37 scanf("%lf%lf%lf",&l,&d,&s); 38 ans=solve(); 39 printf("%.2lf\n",ans); 40 } 41 return 0; 42 }
不怕路长,只怕心老.