hdu 5826 physics

51 篇文章 0 订阅
12 篇文章 0 订阅

physics

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


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
 


这道题应该是物理题,结论是最终的v=根号下2ct+v0*v0;当然也可以用积分的思想来得到,因此题目里给的方向啊位置啊都没什么用..,然后就是按照初速度排序就可以了.但是这道题我们却tle了20+次,然而原因很搞笑,hdu的判题系统将re报成了tle,明明是数组我们开小了,应该是报数组越界的,但却报了超时,就莫名其妙的罚时了20多次.....感觉做题目还是要严谨一点为好..




#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
struct ball{
	long long int v;
	int p;
	int d;
	double v1;
};
bool cmp1(ball x,ball y)
{    
     return x.v<=y.v;
}		
ball b1[111111];
int main(){
	int T ;
	cin>>T;
	while(T--)
	{
		int num,C;
		scanf("%d%d",&num,&C);
		int i,j,k;
		for(i=1;i<=num;i++)
		{
			scanf("%lld%d%d",&b1[i].v,&b1[i].p,&b1[i].d);
		}
		int que;long long int time;
			int rank;
		cin>>que;
		sort(b1+1,b1+1+num,cmp1);
		for(i=1;i<=que;i++)
		{
			scanf("%lld%d",&time,&rank);
			b1[rank].v1=sqrt(2*C*1.0*time+b1[rank].v*b1[rank].v*1.0);
			printf("%.3lf\n",b1[rank].v1);
	    }
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值