physics HDU - 5826(数学)

There are n balls on a smooth horizontal straight track. The track can be considered to be a number line. The balls can be considered to be particles with the same mass.

At the beginning, ball i is at position Xi. It has an initial velocity of Vi and is moving in direction Di.(Di1,1)
Given a constant C . At any moment, ball its acceleration Ai and velocity Vi have the same direction, and magically satisfy the equation that AiVi=C.
As there are multiple balls, they may collide with each other during the moving. We suppose all collisions are perfectly elastic collisions.

There are multiple queries. Each query consists of two integers t and k. our task is to find out the k-small velocity of all the balls t seconds after the beginning.

  • Perfectly elastic collision : A perfectly elastic collision is defined as one in which there is no loss of kinetic energy in the collision.
    Input
    The first line contains an integer T, denoting the number of testcases.

For each testcase, the first line contains two integers n<=105 and C<=109 .
n lines follow. The i-th of them contains three integers Vi,Xi,Di.Vi denotes the initial velocity of ball i. Xi denotes the initial position of ball i. Di denotes the direction ball i moves in.

The next line contains an integer q<=105 , denoting the number of queries.
q lines follow. Each line contains two integers t<=109 and 1<=k<=n .
1<=Vi<=105,1<=Xi<=109
Output
For each query, print a single line containing the answer with accuracy of 3 decimal digits.
Sample Input
1
3 7
3 3 1
3 10 -1
2 7 1
3
2 3
1 2
3 3
Sample Output
6.083
4.796
7.141
也是比较水的题,题目大意是在一条直线上,有n个球,各自有一定的初速度,和方向(也就是说球与球之间会发生碰撞,为弹性碰撞),并且每个球的速度和加速度乘积为一个常数,那天我在的话就把这题给a了,唯一的难点可能就是积分吧,关于碰撞,只要把他当称两球相互穿过就可以了,如果只根据动量守恒定律那么速度是可以抵消的,但是在这里还得遵循能量守恒定律,没有能量损失,并且在质量相等的情况下,两者速度交换即可,因为球都是一样的,就当作相互穿过就好了
现在看积分:

viA=C
dvdt=A=Cv

移向:
vdv=Cdt
两边同时积分有:
vxvivdv=Ctx0dt

得:
v2xv2i2=Ctx

所以:
vx=v2i+2Ctx

至于询问,只要从小到大排序即可,因为这个速度函数是递增的,经过相同时间,他们的大小关系不会改变
代码:

#include
#include
#include
#include
#include
#include
#include
#define N 100005
#define mod 530600414
using namespace std;
int a[100005];
int n,c;
int main()
{
    int t;
    int m;
    int x,y;
    int time,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&c);
        for(int i=1;i<=n;i++)
            scanf("%d%d%d",a+i,&x,&y);
        sort(a+1,a+1+n);
        scanf("%d",&m);

        while(m--)
        {
            scanf("%d%d",&time,&k);
            printf("%.3lf\n",sqrt((double)a[k]*a[k]+2*c*(double)time));
        }
    }
    return 0;
}

你可能感兴趣的:(水题,数学)