physics
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
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.(Di∈−1,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 Ai * Vi = 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.
At the beginning, ball i is at position Xi. It has an initial velocity of Vi and is moving in direction Di.(Di∈−1,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 Ai * Vi = 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 <= 10^5 and C <= 10^9.
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 <= 10^5, denoting the number of queries.
q lines follow. Each line contains two integers t <= 10^9 and 1<=k<=n.
1<=Vi<=10^5,1<=Xi<=10^9
For each testcase, the first line contains two integers n <= 10^5 and C <= 10^9.
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 <= 10^5, denoting the number of queries.
q lines follow. Each line contains two integers t <= 10^9 and 1<=k<=n.
1<=Vi<=10^5,1<=Xi<=10^9
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个球和一个c,每个球质量相同,满足v*a=c,a为加速度,每个球的初始位置,初速度和初始方向,q个询问,每个询问是t秒时刻第k小的速度,小球相撞都是弹性碰撞。题解:跟poj的蚂蚁那道题很相似,当两个小球相撞时,他们的速度会交换,加速度也跟着交换,所以我们对速度排下序,对于每次询问,找出第k个小的初速度,算出他的末速度即可。弹性碰撞没有能量损失,所以动量和动能都守恒,设相撞的小球第一个初速度为v1,末速度为v3,第二个小球初速度为v2,末速度为v4,则能推出来以下公式。
这是证明,接下来是算速度。
代码解决即可~#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; long long n; double c; double v[100005]; int main(){ long long t; scanf("%lld",&t); while(t--){ scanf("%lld%lf",&n,&c); long long i,j,tt; for(i=1;i<=n;i++){ scanf("%lf%lld%lld",&v[i],&j,&tt);//方向和坐标都没用,因为相撞也不会影响速度 } long long t,k,ddsds,sss; scanf("%lld",&ddsds); sort(v+1,v+1+n); for(i=1;i<=ddsds;i++){ scanf("%lld%lld",&sss,&k); printf("%.3f\n",sqrt(2*c*sss+v[k]*v[k])); } } return 0; }