ACdream区域赛指导赛之手速赛系列(4) C Captain Hammer
来源:互联网 发布:java 获取locale 编辑:程序博客网 时间:2024/06/09 19:31
题目:
Captain Hammer
Problem Description
The Hamjet is a true marvel of aircraft engineering. It is a jet airplane with a single engine so powerful that it burns all of its fuel instantly during takeoff. The Hamjet doesn't have any wings because who needs them when the fuselage is made of a special Wonderflonium isotope that makes it impervious to harm.
Piloting the Hamjet is a not a job for your typical, meek-bodied superhero. That's why the Hamjet belongs to Captain Hammer, who is himself impervious to harm. The G-forces that the pilot endures when taking a trip in the Hamjet are legen-dary.
The Hamjet takes off at an angle of θ degrees up and a speed of V meters per second. V is a fixed value that is determined by the awesome power of the Hamjet engine and the capacity of its fuel tank. The destination is D meters away. Your job is to program the Hamjet's computer to calculate θ given V and D.
Fortunately, the Hamjet's Wondeflonium hull is impervious to air friction. Even more fortunately, the Hamjet doesn't fly too far or too high, so you can assume that the Earth is flat, and that the acceleration due to gravity is a constant 9.8 m/s^2 down.
Input
The first line of the input gives the number of test cases, T.
T lines follow. Each line will contain two positive integers -- V and D.
1 ≤ T ≤ 4500
1 ≤ V ≤ 300
1 ≤ D ≤ 10000
It is guaranteed that each test case will be solvable.
Output
For each test case, output one line containing "Case #x: θ", where x is the case number (starting from 1) and θ is in degrees up from the the horizontal.
If there are several possible answers, output the smallest positive one.
An answer will be considered correct if it is within 10^-6 of the exact answer, in absolute or relative error.
Sample Input
398 98098 490299 1234
Sample Output
Case #1: 45.0000000Case #2: 15.0000000Case #3: 3.8870928
传送门:点击打开链接
解题思路:
这是一个抛物线运动,根据中学的物理知识,我们可以推出公式,sin2θ = G*D/(V*V),我们需要求出θ(0<=θ<=π/2),需要用二分求,直接用θ的表达式会出现精度问题。
代码:
#include <cstdio>#include <cmath>#include <iostream>using namespace std; typedef double DB;const DB PI = 4 * atan(1.0);const DB G = 9.8;const DB EPS = 1e-10; int main(){ int t, w = 1; DB v, d, ans; // printf("%.7f\n",90/PI*asin(0.5)); scanf("%d", &t); while(t--) { scanf("%lf%lf", &v, &d); DB l = 0, r = PI/2.0, m = G*d/v/v; while(r-l >= EPS) { DB mid = (l + r) / 2.0; if(2*mid <= PI/2.0) { if(sin(2*mid) >= m) r = mid; else l = mid; } else { if(sin(2*mid) >= m) l = mid; else r = mid; } ans = mid; } printf("Case #%d: %.7f\n", w++, ans*180/PI); } return 0;}
- ACdream区域赛指导赛之手速赛系列(4) C Captain Hammer
- ACdream区域赛指导赛之手速赛系列(4)题解
- ACdream区域赛指导赛之手速赛系列(4)
- ACdream区域赛指导赛之手速赛系列(2)
- ACdream区域赛指导赛之手速赛系列(5) 题解
- ACdream区域赛指导赛之手速赛系列(6)
- ACdream区域赛指导赛之手速赛系列(6) A.
- ACdream区域赛指导赛之手速赛系列(7)
- ACdream区域赛指导赛之手速赛系列(5) 解题报告 A C D
- ACdream区域赛指导赛之手速赛系列(4) A Bad Horse
- ACdream区域赛指导赛之手速赛系列(4) E Tic-Tac-Toe-Tomek
- ACdream区域赛指导赛之手速赛系列(6) 解题报告
- ACdream区域赛指导赛之专题赛系列(1)の数学专场
- ACdream 1118 Captain Hammer (物理题)
- ACdream 区域赛指导赛之专题赛系列(1)の数学专场 A - EOF女神的相反数 (反转2进制)
- Captain Hammer-google
- Google Code Jam Notes - Captain Hammer - Java
- ACdream原创群赛(11)の风神日华神专场 C.神奇的%系列一
- POJ3468_A Simple Problem with Integers(线段树/成段更新)
- ZOJ-1586 QS Network
- HDU2566 统计硬币
- Objective-C NSDictionary & NSSet
- Checker Challenge(dfs深度搜索 打印八皇后)
- ACdream区域赛指导赛之手速赛系列(4) C Captain Hammer
- Sublime-Text2 在Linux下的安装
- java大数的基本函数
- 【读书笔记】当析构函数遇到多线程 ── C++中线程安全的对象回调
- 【Nutch2.2.1基础教程之1】nutch相关异常
- JavaScript学习 jquery10 焦点事件
- Delphi XE4 iOS应用程序开发(1)
- WebSocket初探
- 输入的区别