Problem J: angry_birds_again_and_again
Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 66 Solved: 48
[ Submit][ Status][ Web Board]
Description
The problems called "Angry Birds" and "Angry Birds Again and Again" has been solved by many teams in the series of contest in 2011 Multi-University Training Contest.
This time we focus on the yellow bird called Chuck. Chuck can pick up speed and distance when tapped.
You can assume that before tapped, Chuck flies along the parabola. When tapped, it changes to fly along the tangent line. The Chuck starts at the coordinates (0, 0). Now you are given the coordinates of the pig (Px, 0), the x-coordinate of the tapping position (Tx) and the initial flying angle of Chuck (α).
∠AOx = α
Please calculate the area surrounded by Chuck’s path and the ground.(The area surrounded by the solid line Please calculate the area surrounded by Chuck’s path and the ground.(The area surrounded by the solid line O-Tapping position-Pig-O)
This time we focus on the yellow bird called Chuck. Chuck can pick up speed and distance when tapped.
You can assume that before tapped, Chuck flies along the parabola. When tapped, it changes to fly along the tangent line. The Chuck starts at the coordinates (0, 0). Now you are given the coordinates of the pig (Px, 0), the x-coordinate of the tapping position (Tx) and the initial flying angle of Chuck (α).
Please calculate the area surrounded by Chuck’s path and the ground.(The area surrounded by the solid line Please calculate the area surrounded by Chuck’s path and the ground.(The area surrounded by the solid line O-Tapping position-Pig-O)
Input
The first line contains only one integer T (T is about 1000) indicates the number of test cases. For each case there are two integers, px tx, and a float number α.(0 < Tx ≤ Px ≤ 1000, 0 < α < ) .
Output
One line for each case specifying the distance rounded to three digits.
Sample Input
1
2 1 1.0
Sample Output
0.692
抛物线f(x)=ax^2+bx+c,斜率为导数f’(x)=2ax+b。因为经过原点,所以c=0,又知道原点的斜率为tan(α)=b。
a的话,知道了tx和px组成的三角形,在tx处的斜率为f(tx)/(px-tx),注意此时斜率为负数。
知道了a,b,c就可以求定积分来计算抛物线的面积了。
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int t;
int px, tx;
double s;
int main()
{
scanf("%d", &t);
while (t--){
scanf("%d%d%lf", &px, &tx, &s);
double b = tan(s);
double a = (b * px) / (tx * tx - 2 * tx * px);
double areat = 1.0 / 3.0 * a * tx * tx * tx + 1.0 / 2.0 * b * tx * tx;
double areas = 1.0 / 2.0 * (px - tx) * (a * tx * tx + b * tx);
printf("%.3lf\n", areat + areas);
}
return 0;
}