physicsTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 823 Accepted Submission(s): 455
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.
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
Output
For each query, print a single line containing the answer with accuracy of 3 decimal digits.
Sample Input
Sample Output
Author
学军中学
Source
|
思路:两个小球完全弹性碰撞之后,它们的速度会交换,所以不用考虑小球的初始位置和初始方向,只需要考虑小球的速度。
根据题意我们可以列出方程
a=dvdt=Cv
,得
∫vv0vdv=∫t0Cdt
,得
v2−v20=2Ct
,其中
v0
为小球初始速度,,
v
为t秒后小球的速度,这样就可以解出来了,要求第
k
个,因为小球的速度是不断增加,那么我们将小球按照初始速度排序,那么最后直接求
v[k]
在
t
秒后的速度即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
const int M=1e6+10;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int i,j,k,n,m;
double c,tt;
double v[M];
double vv[M];
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d %lf",&n,&c);
for(int i=1;i<=n;i++){
int x,d;
scanf("%lf%d%d",&v[i],&x,&d);
}
sort(v+1,v+n+1);
int q;
scanf("%d",&q);
for(int i=1;i<=q;i++){
scanf("%lf%d",&tt,&k);
printf("%.3lf\n",vv[k]=sqrt(v[k]*v[k]+2.0*tt*c));
}
}
return 0;
}
|