问题 F: A Brave Archery Tournament
作者:互联网
#### 题目描述
Merida wants some help in predicting her score for an archery tournament. When she fires an arrow, we can compute that arrow’s trajectory given a quadratic formula and the arrow’s initial position and velocity. Then we can compute where on the target it will lie.
An arrow that lands strictly within 1 unit of the center of the target is worth 5 points, if it lands strictly within 2 units it is worth 3 points, and if it lands strictly within 3 units it is worth 1 point. Any further away and the shot is worth 0 points.
We will represent the archery range as a 2D plane. Merida will always shoot directly toward the target, but may miss above or below.
The center of the target is always at the point (0,0) and it extends up and down along the y-axis. Given the arrow’s initial position and velocity, compute the point value for the shot.
The formulas that govern the arrows’ path are:
x = vt + x0
y = wt − 5t2 + y0
Where t is the time since the arrow was fired in seconds, x and y are the arrow’s x and y coordinates
at time t, v and w are the x and y components of the arrow’s initial velocity, and x0 and y0 are the arrow’s initial position.
#### 输入
The first line of input will be a single integer n ≤ 10, 000; n test cases will follow. Each test case consists of two lines. The first line will be two integers x and y, the x and y coordinates of the arrow’s initial position.
The second line will be two integers v and w, the x and y components of the arrow’s initial velocity as per the formulas above.
#### 输出
For each test case, output a single line with a single integer, the number of points for that shot according to the point assignments above.
#### 样例输入 [Copy](javascript:CopyToClipboard($('#sampleinput').text()))
```
2
-10 0
10 5
-10 0
9 4
```
#### 样例输出 [Copy](javascript:CopyToClipboard($('#sampleoutput').text()))
```
5
3
```
AC代码
**遇到的问题**
计算时间t的时候总是带入y,其实t与y没有关系,物理比较烂看不出来...
一个单位范围内不应该包含1
```
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int T;
cin >> T;
while(T -- )
{
double x0, y0, v, w;
cin >> x0 >> y0 >> v >> w;
double t = abs(x0 / v);
double y = w * t - 5 * t * t + y0;
y = abs(y);
if(y < 1)cout << 5 << endl;
else if(y < 2)cout << 3 << endl;
else if(y < 3)cout << 1 << endl;
else cout << 0 << endl;
}
return 0;
}
```
标签:Archery,Brave,Tournament,initial,will,####,arrow,y0,x0 来源: https://www.cnblogs.com/jw-zhao/p/14664249.html