山东省第五届ACM省赛题——angry_birds_again_and_again(计算几何)

来源:互联网 发布:C语言exit(-1) 编辑:程序博客网 时间:2024/05/29 23:23

题目描述
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 O-Tapping position-Pig-O)
输入
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 < α <  ) .
输出
One line for each case specifying the distance rounded to three digits.
示例输入
1
2 1 1.0
示例输出
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 <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>using namespace std;int main(){    double px,tx,alpha,ans,b,a;    int T;    scanf("%d",&T);    while(T--)    {        scanf("%lf%lf%lf",&px,&tx,&alpha);        b=tan(alpha);        //cout<<b<<endl;        a=(b*px)/(tx*tx-2*px*tx);        //cout<<a<<endl;        ans=1.0/3.0*a*pow(tx,3)+0.5*b*tx*tx;        ans+=0.5*(px-tx)*(a*tx*tx+b*tx);        printf("%.3lf\n",ans);    }    return 0;}
0 0