2016多校训练Contest8: 1006 physics hdu5826

来源:互联网 发布:优美的句子 知乎 编辑:程序博客网 时间:2024/04/28 02:24

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.(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 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
13 73 3 13 10 -12 7 132 31 23 3
 

Sample Output
6.0834.7967.141

数轴上有若干小球,他们互相碰撞为弹性碰撞。给定一个常数C,满足加速度a*速度v=C, q个询问,问t时刻第k小速度的球速度是多少


首先。因为是弹性碰撞。所以我们可以直接当成穿过,因此题目中的位置和方向是无用信息

然后考虑怎么算速度。一种方法是微积分。

另外一种方法是观察这个式子v*a=C,考虑功率式v*f=P,因此v*f/m=C=P/m,因为m为定值,因此功率不变。所以所做的功全部转化为动能

上面两种方法均可以算出t时刻速度为Vt=sqrt(2*c*t+v0*v0)

可以发现这个速度的相对大小不变,因此一开始排序,询问直接求出即可

#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;double a[200001];inline double cal(double v0,double c,double t){return sqrt(double(2)*c*t+double(v0)*double(v0));}int main(){int T;scanf("%d",&T);while(T>0){T--;int n,c;scanf("%d%d",&n,&c);int i,x,t;for(i=1;i<=n;i++){scanf("%lf",&a[i]);scanf("%d%d",&x,&x);}int m;scanf("%d",&m);sort(a+1,a+1+n);for(i=1;i<=m;i++){scanf("%d%d",&t,&x);printf("%.3lf\n",cal(a[x],c,t));}}return 0;}



0 0