zoukankan      html  css  js  c++  java
  • Toxophily

    Problem Description
    The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballrooms KTV rooms, fishing, climbing, and so on.
    We all like toxophily.

    Bob is hooked on toxophily recently. Assume that Bob is at point (0,0) and he wants to shoot the fruits on a nearby tree. He can adjust the angle to fix the trajectory. Unfortunately, he always fails at that. Can you help him?

    Now given the object's coordinates, please calculate the angle between the arrow and x-axis at Bob's point. Assume that g=9.8N/m.

    Input
    The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case is on a separated line, and it consists three floating point numbers: x, y, v. x and y indicate the coordinate of the fruit. v is the arrow's exit speed.
    Technical Specification

    1. T ≤ 100.
    2. 0 ≤ x, y, v ≤ 10000.

    Output
    For each test case, output the smallest answer rounded to six fractional digits on a separated line.
    Output "-1", if there's no possible answer.

    Please use radian as unit.

    Sample Input
    3
    0.222018 23.901887 121.909183
    39.096669 110.210922 20.270030
    138.355025 2028.716904 25.079551

    Sample Output
    1.561582
    -1
    -1
    题意:鲍勃射箭(注意实在平面射箭,刚开始我也理解错了,但是后来看到没有高度所以,不可能在空间),鲍勃在(0,0),给出苹果的坐标,和箭飞的速度,求最小角度;
    解题思路:现在0-pi之间用三分求出最大角度,要是最大角度都飞不到苹果的地方就不可能射到就输出-1,否则,再在0-在大角度之间求最小角度;
    感悟:二分这里没什么解题思路可以写,无非就是控制精度的,懂了题意就用二分或三分解;
    代码(g++)
    #include
    #include
    #include
    #define g 9.8
    #define pi 3.1415926535897932384626433832795028841971693993751058209
    //这次就不听pi精度还不够
    double x,y,v;
    double  distance_y(double s)
    {
        return v*sin(s)*x/(v*cos(s))-4.9*x*x/(v*cos(s)*v*cos(s));
    }
    int main()
    {
        //freopen("in.txt", "r", stdin);
        double mid1,mid2,first,endn,sum1,sum2;
        int n;
        scanf("%d",&n);
        for(int i=0;i
        {
            scanf("%lf%lf%lf",&x,&y,&v);
            first=0;
            endn=pi;//再大就反向Q了;
            while(fabs(endn-first)>1e-8)//三分来判断最大的那个角度
      {
       mid1=first+(endn-first)/3;
       mid2=endn-(endn-first)/3;
       sum1=distance_y(mid1);
       sum2=distance_y(mid2);
       if(sum1>sum2)
        endn=mid2;
       else
        first=mid1;
      }
      if(distance_y(first)
      {
       printf("-1 ");
       continue;
      }
      first=0;
      while(fabs(endn-first)>1e-8)//二分找最小值
      {
       mid1=(endn+first)/2;
       sum1=distance_y(mid1);
       if(sum1
        first=mid1;
       else
        endn=mid1;
      }
      printf("%.6lf ",endn);
        }
    }
  • 相关阅读:
    JavaScript 格式化数字
    浅析C#中单点登录的原理和使用
    从银行转账失败到分布式事务:总结与思考
    计算机网络资料
    阿里巴巴Java开发规约插件p3c详细教程及使用感受
    程序员如何打造属于自己的云笔记服务
    sql server2016里面的json功能
    mac pro 开启三只滑动选中文本
    技术网站
    idea gradle项目导入
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5781640.html
Copyright © 2011-2022 走看看