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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
const int N=100005;
double v[N];
double getV(double v1,double t,double c){
return sqrt(v1*v1+2*c*t);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
double c;
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);
while(q--){
double t;
int k;
scanf("%lf %d",&t,&k);
printf("%.3lf\n",getV(v[k],t,c));
}
}
}
题意:直线上有n个等质量小球,每个小球有初速度v0,初始位置x,移动方向d,并且满足加速度a*v=C,C为常数,且小球间发生的都是完全弹性碰撞求时间t后速度第k小的小球速度;
分析题意,完全弹性碰撞在等质量的情况下即交换速度,两球相撞后交换速度,因为题目没有让我们求哪一个球的速度,因此可以当成两个球互相穿过对方继续向前走;
将公式a*v=C转化,dv/dt*v=c -> vdv=Cdt ->∫(v0~v)vdv=C∫(0~t)dt ->v^2=v0^2+2Ct,开根号将每个未知量带入即可;
因为要求第k小,所以我们需要将v排序,但是v是浮点数排序起来非常耗时,因此我们可以在v0时就进行排序,结果依旧不变;
记住sort的用法是第一个参数参加排序,第二个参数不参加;