hdu5826
来源:互联网 发布:航天金税官网开票软件 编辑:程序博客网 时间:2024/05/29 09:31
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 directionDi.(Di∈−1,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.
At the beginning, ball i is at position Xi. It has an initial velocity of Vi and is moving in direction
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
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
思路:球碰撞之后速度不会变化,跟原先状态一样,然后可以找出t时刻的速度(2*c*t+v*v)的 开方,所以直接给初始速度排个序就可以了;
前面一直TLE,后面才发现数组开小了。
代码:
#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
- hdu5826
- HDU5826 physics
- HDU5826 physics
- hdu5826 物理+积分
- 【HDU5826】physics(物理题 + 数学题)
- 【1】【物理/积分】HDU5826 physics
- hdu5826 physics(物理推公式)
- 2016多校联赛 hdu5826 physics 数学题
- 2016多校训练Contest8: 1006 physics hdu5826
- [HDU5826] physics [2016 Multi-University Training Contest 8(2016多校联合训练8) 1006]
- UEditor上传图片和上传文件(基于jquery)
- 20170719
- HTML5事件器
- Java基本类型和包装类型总结
- python库管理工具pip,pygame安装及环境变量配置
- hdu5826
- 安装.net framework 4.0失败,出现HRESULT 0xc8000222错误代码
- R语言之三种左连接
- Ehcache缓存框架入门级使用
- 堕落退散之日,奋斗开始之时!
- PHP获取curl传输进度
- 程序员,为什么写不好一份简历?
- JavaScript-回调函数
- 7月19号牛客网做题笔记