杭电多校赛contests8 1006 physics

来源:互联网 发布:红鸟棋牌源码需要授权 编辑:程序博客网 时间:2024/06/03 22:58

                                             physics

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

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 directionDi.(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

 

这道题看上去挺吓人的,但其实一点也不吓人,分析分析发现十分简单,当时有500多个队伍过了这题,所以应该把它归为水题一类,有助于你复习复习物理。

这道题就是说,已知几个完全一样的小球,大小质量相同,他们初始的运动方向已知,初始速度已知,初始位置已知,他们碰撞遵循牛顿第四。。。,不对,应该是当成完全弹性碰撞,两个运动的小球相碰,如果是完全弹性碰撞是有公式的,你也可以用动能定理什么的,反正没能量损失,最后推出V1=V20,V2=V10也就是说两个小球碰撞后速度就交换了,最重要一点是,题目说了每时每刻小球的加速度A*V=C,C是已知的,这时候我们可以对加速度积分一下,dv/dt=C/V,公式就出来了,Vt=sqrt(2Ct+v0^2),然后写一写程序,就过了。。。

不过当时我不会,因为我太菜了,不会学以致用,问了问同学这种题目,他给我在dv/dt=C/V时候V是用V0带入的,那可是个常数啊,所以一开始公式不对,我也想不出来,后来百度了一下这种积分,才明白。。。

代码如下:

#include<cstdio>#include<algorithm>#include<cmath>using namespace std;int main(){    long long T,n,c,i,a[100005]={0},t,k,q;    scanf("%lld",&T);    while(T--)    {        scanf("%lld%lld",&n,&c);        for(i=0;i<n;i++)            scanf("%lld%lld%lld",&a[i],&t,&t);        sort(a,a+n);        scanf("%lld",&q);        while(q--)        {            scanf("%lld%lld",&t,&k);            printf("%.3lf\n",sqrt(2*c*t+a[k-1]*a[k-1]));        }    }    return 0;}


这里记得要用long long,否则在sqrt里面最多可以达到10的十八次方,int是存不下的,就会不明觉wa一发

 

0 0
原创粉丝点击