题目链接:

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.(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.

 
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;
}

  

最新文章

  1. mac brew install redis 报错
  2. 33条C#和.NET经典面试题目及答案
  3. ActiveMQ_监听器(四)
  4. Win7 64位 VS2013环境编译boost1_58_0
  5. hdu4825 字典树 XOR
  6. 【风马一族_Android】 图能
  7. python 发邮件 utf-8
  8. iOS-NSAttributedString自定义文字变色
  9. SGU 548 Dragons and Princesses
  10. java 重写的学习
  11. java复习要点(一)------- java语言的特点、java的工作原理、配置环境变量、java命令的使用
  12. 三、Spring Boot 多数据源配置
  13. C#使用Socket实现一个socket服务器与多个socket客户端通信
  14. git 撤销没有提交的变化
  15. 为何学习matplotlib-【老鱼学matplotlib】
  16. SQL中内连接和外连接的区别
  17. Angular4 组件间通讯
  18. Unity3D热更新之LuaFramework篇[03]--prefab加载和Button事件
  19. Hive| DDL| DML
  20. 面试汇总——说一下CSS盒模型

热门文章

  1. nodejs读取配置文件
  2. 有一个长为n的数组A,求满足0≤a≤b&lt;n的A[b]-A[a]的最大值。 给定数组A及它的大小n,请返回最大差值。
  3. 果园里有一堆苹果,一共n头(n大于1小于9)熊来分,第一头为小东,它把苹果均分n份后,多出了一个,它扔掉了这一个,拿走了自己的一份苹果,接着第二头熊重复这一过程,即先均分n份,扔掉一个然后拿走一份,以此类推直到最后一头熊都是这样(最后一头熊扔掉后可以拿走0个,也算是n份均分)。问最初这堆苹果最少有多少个。
  4. 精彩回顾 HUAWEI HiAI 亮相华为北研所
  5. Selenium3 Python3 Web自动化测试从基础到项目实战之一启动不同的浏览器及配置
  6. Linux下Kafka单机安装配置方法
  7. CentOS6.5安装MySQL5.6 过程记录
  8. Django的标准库django.contrib包介绍(转)
  9. notHere 对框架解决方案的框架预期处理
  10. python cookbook第三版学习笔记八:解析码流