[ACM] sdut 2877 angry_birds_again_and_again (簡單數學積分)
angry_birds_again_and_again
Time Limit: 2000ms Memory limit: 65536K 有疑問?點這裡^_^
題目描述
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喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcyBwYXRoIGFuZCB0aGUgZ3JvdW5kLihUaGUgYXJlYSBzdXJyb3VuZGVkIGJ5IHRoZSBzb2xpZCBsaW5lIE8tVGFwcGluZyBwb3NpdGlvbi1QaWctTykKCgo8aDI+CsrkyOs8L2gyPgoKVGhlIGZpcnN0IGxpbmUgY29udGFpbnMgb25seSBvbmUgaW50ZWdlciBUIChUIGlzIGFib3V0IDEwMDApIGluZGljYXRlcyB0aGUgbnVtYmVyIG9mIHRlc3QgY2FzZXMuIEZvciBlYWNoIGNhc2UgdGhlcmUgYXJlIHR3byBpbnRlZ2VycywgcHggdHgsIGFuZCBhIGZsb2F0IG51bWJlciCmwS6jqDA/PD9UeD+h3D9QeD+h3D8xMDAwLCAwPzw/psE/PD8gPGltZyBzcmM9"http://www.2cto.com/uploadfile/2014/1128/20141128110127869.png" width="8" height="19" alt="\">)
.
輸出
One line for each case specifying the distance rounded to three digits.
示例輸入
1
2 1 1.0
示例輸出
0.692
提示
來源
2014年山東省第五屆ACM大學生程序設計競賽
解題思路:
設方程 y=ax^2+bx+c ,圖中曲線經過原點,所以c=0.
對方程求導 y'=2ax+b , y'代表斜率,那麼原點(0,0)這一點,代人y'=b,即該點的斜率,根據題意b=tan( α)
如圖:在題目中x=tx這一點時,容易混,記tx為t, 圖中曲線x=t這一點,該點的斜率為 2at+b . 注意斜率是負的
三角形豎著的直角邊除以橫著的直角邊(p-t)的值的相反數即為斜率 2at+b
豎著的直角邊值為 at^2+bt (將t帶入原方程),橫著的直角邊為p-t,則有式子
2at+b= - ( at^2+bt)/(p-t)
解出a,這樣方程中a,b的值都有了。
那麼題目所求的面積即為 曲線覆蓋面積 從 0到t積分 積分函數為(ax^2+bx) ,再加上三角形的面積 0.5*(p-t)*(at^2+bt)
代碼:
#include
#include
#include
using namespace std;
double px,tx,jiao;
double a,b;
int main()
{
int t;cin>>t;
while(t--)
{
cin>>px>>tx>>jiao;
b=tan(jiao);
double m=px-tx;
a=(-b*tx-b*m)/(2*tx*m+tx*tx);
double ans;
ans=(1/3.0)*a*tx*tx*tx+0.5*b*tx*tx+0.5*(px-tx)*(a*tx*tx+b*tx);
cout<