HDU5826 physics

physics

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


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
 

Author
学军中学
 

Source
题意:一个坐标轴上有一堆点,知道他们的初始位置,方向,和速度,然后所有点的速度与加速度之积是定值,如果两个点碰撞的话是完全弹性碰撞,然后问时间为t的时候速度第k小的点的速度是多少。

题解:因为是完全弹性碰撞,那么碰撞以后其实只是速度交换,所有碰撞不碰撞完全没影响。然后考虑2个点A,B  初始速度VA>VB 那么因为C=v*a,所以VB肯定是先加速到VA然后再按照A的情况加速,所以如果一开始VA>VB,那么VA会一直大于VB。

这样下来我们的问题就变成了求t时初始速度第k小的速度为多少,我们从C=v*a入手

a = dv/dt

a = C/v

我们可以把第二个式子带进第一个然后积分一下很容易就能求得t时的速度vt = sqrt(v0*v0+2tC).

//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#define fur(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef long long ll;
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
// (づ°ω°)づe★
//-----------------------------------------------------------------
const int maxn = 1e5+5;
int v[maxn];
int C;
int q,k,t;
int main(){
    int T;
    gn(T);
    while(T--){
        int n;
        gn(n);gn(C);
        fur(i,1,n){
            gn(v[i]);gn(q);gn(q);
        }
        sort(v+1,v+1+n);
        gn(q);
        fur(i,1,q){
            gn(t);gn(k);
            double ans = sqrt(1ll*v[k]*v[k]+2ll*C*t);
            printf("%.3lf\n",ans);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值