注意h > w的时候交换,还有就是注意一下转化double,错了好几次。。。算法就是解方程。。精度倒是不卡。
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <string> 5 using namespace std; 6 #define PI 3.1415926535898 7 #define eps 1e-13 8 double fun(double x) 9 { 10 return x*PI/180; 11 } 12 int main() 13 { 14 int h,w,a,t; 15 double k1,k2,x,y,ha,sp,ans; 16 scanf("%d%d%d",&w,&h,&a); 17 if(h > w) 18 { 19 t = h; 20 h = w; 21 w = t; 22 } 23 ha = fun(a); 24 if(ha > fun(90.0)) 25 { 26 ha = PI - ha; 27 } 28 sp = 2*(atan(h*1.0/w)); 29 if(ha < sp) 30 { 31 k1 = (1 + 1/cos(ha)); 32 k2 = tan(ha); 33 x = (h*k1-w*k2); 34 y = (h*k2-w*k1); 35 ans = (double)h*w - k2*(x*x + y*y)/((k1*k1-k2*k2)*(k1*k1-k2*k2)); 36 } 37 else 38 { 39 ans = (double)h*h/sin(ha); 40 } 41 printf("%lf\n",ans+eps); 42 return 0; 43 }