zoukankan      html  css  js  c++  java
  • hdu 2298 Toxophily(数学题)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2298

    题意:斜抛运动。。。起点坐标(0,0),终点坐标(x,y),速度v,g=9.8,求最小弧度角。(不存在输出-1)

    思路:总方程 g*x^2(tanθ)^2 - 2*x*v^2*tanθ + 2*y*v^2 + g*x^2 = 0;

     求tanθ。 ans = atan(tanθ);

     1 #include <cstdio>
     2 #include <cmath>
     3 
     4 #define g 9.8
     5 #define PI (double)acos(-1.0)
     6 
     7 int main()
     8 {
     9     int t;
    10     double x, y, v, ans;
    11     scanf("%d",&t);
    12     while(t--)
    13     {
    14         scanf("%lf%lf%lf",&x,&y,&v);
    15         if(x==0 && y==0) printf("0 ");
    16         else if(v==0) printf("-1 ");
    17         else if(x==0 && v*v<2*g*y) printf("-1 ");
    18         else if(x==0 && v*v>=2*g*y) printf("%.6lf ",PI/2);
    19         else
    20         {
    21             int flag = 0;
    22             double a = g*x*x, b = -2*x*v*v, c = 2*y*v*v+g*x*x;
    23             double temp = b*b-4*a*c;
    24             if(temp==0)
    25             {
    26                 temp = -b/(2*a);
    27                 if(temp>0) {ans = atan(temp); flag = 1;}
    28             }
    29             else if(temp>0)
    30             {
    31                 double ans1 = (-b+sqrt(temp))/(2*a);
    32                 double ans2 = (-b-sqrt(temp))/(2*a);
    33                 if(ans1>0 && ans2>0)
    34                 {
    35                     ans1 = atan(ans1); ans2 = atan(ans2);
    36                     ans = ans1 < ans2 ? ans1 : ans2;
    37                     flag = 1;
    38                 }
    39                 else if(ans1>0)
    40                 {
    41                     ans = atan(ans1); flag = 1;
    42                 }
    43                 else if(ans2 > 0)
    44                 {
    45                     ans = atan(ans2); flag = 1;
    46                 }
    47             }
    48             if(flag==1)
    49                 printf("%.6lf ",ans);
    50             else
    51                 printf("-1 ");
    52         }
    53     }
    54     return 0;
    55 }
    View Code 

     ==================

    数学题要耐心+细心。。 

  • 相关阅读:
    真的是最后一次作业了!!!!
    最后一次总结
    作业十一总结?
    作业十一总结
    实验十总结
    作业9总结
    附加作业
    补交第十次作业
    补交第九次作业
    补交第八次作业
  • 原文地址:https://www.cnblogs.com/byluoluo/p/3472676.html
Copyright © 2011-2022 走看看