杭电OJ 5826 physics

来源:互联网 发布:网络信息自查报告 编辑:程序博客网 时间:2024/05/21 11:15

physics

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


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
 

Author
学军中学
 

Source
2016 Multi-University Training Contest 8
 

Recommend
wange2014
代码:


#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <algorithm>
#include<stdlib.h>
#include<cmath>
#include<iostream>
using namespace std;
int v[500001],d[500001],p[500001];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
         int sum;
         int n,c;
         scanf("%d%d",&n,&c);
         for(int i=1;i<=n;i++)
         {
              scanf("%d%d%d",&v[i],&d[i],&p[i]);
         }
         sort(v+1,v+1+n);
         int m;
         scanf("%d",&m);
         while(m--)
         {
              int t,k;
              scanf("%d%d",&t,&k);
              long long pp=(long long )v[k]*v[k]+t*2.0*c;
              double ans=(double)sqrt(pp);
              printf("%.3lf\n",ans);
         }
    }
    return 0;
}
0 0
原创粉丝点击