hdu-5826 physics(数学)

题目链接:

physics

Time Limit: 6000/3000 MS (Java/Others)  

  Memory Limit: 65536/65536 K (Java/Others)

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个球的初始位置,速度,方向,问t秒之后的第k小的速度是多少;
 
思路:
 
碰撞之后就是交换速度了,对速度大小没什么影响,问题就是求 一个速度的式子;
a=c/v=dv/dt;
vdv=cdt;积分可得v12-v22=2*c*t; 所以v1=sqrt(v22+2*c*t);排个序就好了;
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map>
 
using namespace std;
 
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
 
typedef  long long LL;
 
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}
 
const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e5+10;
const int maxn=5e3+4;
const double eps=1e-12;

double v[N],pos[N],t,c;
int d[N],k,n;

int main()
{
   int T;
   read(T);
   while(T--)
   {
        read(n);
        scanf("%lf",&c);
        For(i,1,n)
        {
            scanf("%lf%lf%d",&v[i],&pos[i],&d[i]);
        }
        sort(v+1,v+n+1);
        int q;
        read(q);
        while(q--)
        {
            scanf("%lf%d",&t,&k);
            printf("%.3lf\n",sqrt(v[k]*v[k]+2*c*t));
        }
   }
    return 0;
}

  

posted @ 2016-08-11 18:45  LittlePointer  阅读(267)  评论(0编辑  收藏  举报