HDU 5826 physics(积分 找规律)——2016 Multi-University Training Contest 8

来源:互联网 发布:什么租房软件最好 编辑:程序博客网 时间:2024/05/21 12:47

传送门

physics

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 95    Accepted Submission(s): 66


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
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 个质量相同的球(可以看作质点),给出每个球的初速度 vi、起

始位置Xi、方向Di,如果这些小球之间进行碰撞的话 是完全弹性碰撞.然后 给出 Q 组询问,每次输出 t 秒时第 k 小的速度是多少.

对任意球的任一时刻而言,速度与加速度同方向,且它们的乘积为定值 av=C.

解题思路:

直接根据公式:av=C,然后设一个速度微元 dv 和一个 时间微元 dt 那么我们可以列出方程:

dv=Cvdt

那么将 v 乘过去可以得到: vdv=Cdt

然后到了这步就可以对两边进行积分得左边的积分上限是 v 积分下限是 v0,右边的积分上限是 t 积分下限是 0

12(v2v20)=Ct

所以得到了公式就是:

v=2Ct+v20

因为让我们求的是第 k 小速度,所以将速度排一下序就行了。。。跟位置和方向没有关系

My Code

/**2016 - 08 - 11 晚上Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e5+5;const LL MOD = 1e9+7;const double e = 2.718281828459;const double eps = 1e-7;const double PI = acos(-1);using namespace std;int x[MAXN], d[MAXN];double v[MAXN];inline bool cmp(int a, int b){    return a > b;}int main(){    int T, n;    double C;    scanf("%d",&T);    while(T--)    {        scanf("%d%lf",&n,&C);        for(int i=1; i<=n; i++)            scanf("%lf%d%d",&v[i],&x[i],&d[i]);        sort(v+1, v+n+1);        int Q;        scanf("%d",&Q);        while(Q--)        {            int  k;            double t;            scanf("%lf%d",&t, &k);            printf("%.3lf\n",sqrt(v[k]*v[k]+2*t*C));        }    }    return 0;}
0 0
原创粉丝点击