题意:有只牛要吃草,现在有个墙挡着,给你绑着牛的绳的长度,墙的长度,绳原点到墙的距离,问牛能在多大的面积里吃草
思路:分为四种情况,详情请看书。被dp卡着这题没做成
#include <iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; #define eps 1e-8 const double PI=acos(-1.0); double l,d,s; double solve(){ if(s-d<eps)//1 return PI*s*s; double dist=sqrt(0.25*l*l+d*d),ans=0; if(s-dist<eps){//2 double angle=acos(d/s); ans=(PI-angle)*s*s+s*d*sin(angle); }else{//3,4 double angle=asin(0.5*l/dist); ans+=(PI-angle)*s*s+0.5*l*d; s-=dist; angle+=0.5*PI; ans+=angle*s*s; if(s+s-l>eps){ double angle1=acos(0.5*l/s); ans-=angle1*s*s-0.5*sin(angle1)*s*l; } } return ans; } int main(int argc, char** argv) { int t; double ans; scanf("%d",&t); while(t--){ scanf("%lf%lf%lf",&l,&d,&s); ans=solve(); printf("%.2lf\n",ans); } return 0; }
soj 1698 Hungry Cow_三角函数,布布扣,bubuko.com
原文:http://blog.csdn.net/neng18/article/details/24121873