博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Toxophily
阅读量:6693 次
发布时间:2019-06-25

本文共 2303 字,大约阅读时间需要 7 分钟。

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\n");
   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\n",endn);
    }
}

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/5781640.html

你可能感兴趣的文章
Nginx服务器部署 负载均衡 反向代理
查看>>
C++学习笔记:指向函数的指针
查看>>
Child Action
查看>>
# 2017-2018-1 20155319 实验五 《通讯协议设计》
查看>>
通用后台管理系统(1)-数据库设计
查看>>
做自适应网页
查看>>
ACM的奇计淫巧_bitset优化
查看>>
centos 配置防火墙操作
查看>>
比亚迪速锐F3专用夏季座套 夏天坐垫 四季坐套
查看>>
Java web 实现 之 Filter分析ip统计网站的访问次数
查看>>
bzoj1303
查看>>
2015.3.12 C#运用正则表达式点滴
查看>>
CSS布局自适应等分比例
查看>>
安装Git
查看>>
设置启动图片LaunchScreen 和 LaunchImage
查看>>
L84
查看>>
L157
查看>>
L156
查看>>
第十周作业
查看>>
win10常用快捷键
查看>>