多校第四场——1011 Kindergarten Physics

Problem Description
Zhang3 a participant of IPhO (Immortal Physics Olympiad). The 0th problem in the contest is as follows.

There are two balls that weigh a kg and b kg respectively. They can be regarded as particles in this problem, as they are small enough. At the very beginning (i.e. t=0), the distance between two balls is d km, and both of them are not moving.

Assuming that only gravitation works in this system (no other objects or other forces considered). The two balls has started moving since t=0. Your task is to calculate the distance between them when t=t0 (s).

Help Zhang3 solve the problem!

The following information might help when solving the problem.

  • Universal gravitation formula: F=G⋅m1⋅m2/r2

  • Gravitational constant: G=6.67430×10−11m3/(kg⋅s2)

Input
The first line of the input gives the number of test cases T(1≤T≤100). T test cases follow.

For each test case, the only line contains four integers a,b,d,t0(1≤a,b,d,t0≤100), representing the mass of the two balls, the initial distance between them, and how much time the balls move.

It is guaranteed that two balls will not collide within (t0+1) seconds.

Output
For each test case, print a line with a real number x, representing that the distance is x km.

Your answers should have absolute or relative errors of at most 10−6.

Sample Input
3
1 2 3 4
7 73 7 68
100 100 1 100

Sample Output
2.99999999999999999982
6.99999999999999974807
0.99999999999993325700

题意:模拟两个质点只在万有引力下的运动

思路:模拟就行,注意精度

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double e = 1e11;
const double G = 6.6743;
long double a,b,d,t;
double d_t;
void go()
{
    d_t = t/1000;
    double aa = G*b/d/d/e;
    double ab = G*a/d/d/e;
    while(t>0)
    {
        d-=aa*d_t*d_t;
        d-=ab*d_t*d_t;
        t-=d_t;
    }
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {

        cin>>a>>b>>d>>t;
        go();
        cout<<setiosflags(ios::fixed)<<setprecision(20)<<d<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43330910/article/details/107773101
今日推荐