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

  

时间: 2024-11-05 15:49:37

hdu-5826 physics(数学)的相关文章

HDU 5826 physics(物理)

HDU 5826 physics(物理) Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   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 con

hdu 5826 physics (物理数学,积分)

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 considere

hdu 5826 physics

水题: 题意:给你n个球,在一维方向上,每个球给三个量,分别为初速度v,初始坐标x,方向(1||-1),每个球会运动,加速度为a,满足a*v=c,c已知,可能会完全碰撞,问第t秒第k小的速度是多少: 想法:第一眼看到a*v=c,立即想到了高中物理的恒定功率,小车的加速阶段的运动模型,设m=1,则a*m*v=c=p:再用动量定理,p*t=1/2*m*v*v-1/2*m*v0*v0,即可得出: 代码: #include <bits/stdc++.h> using namespace std; co

hdu 4811 Ball(数学)

题目链接:hdu 4811 Ball 题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b.问说给定球的数量后,最大得分为多少. 解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值.那么求峰值就要根据球的数量来决定.我们叫得分为峰值的求为最高得分球,它们有很多个.对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是

hdu 5826 (物理) physics

题目:这里 题意:光滑的水平直线上有n个质量相等的小球,已知每个小球的初始位置,初始速度和方向,每个小球的每个时刻的加速度a都满足a*v=c,v是该时刻的速度,c是已知的 常数,小球之间的碰撞是完全碰撞(不明白就百度),然后q个询问,每次询问第t秒时速度第k小的小球速度是多少? 完全碰撞即碰撞后速度交换,速度还是那两个速度,只是不是原来那个球了而已,但这并不时需要考虑的,因为只需要关心速度,所以初始方向以及初始位置什么的都不需要在意, 因为加速度a=c/v,加速度每时每刻都在变,速度每时每刻也在

hdu 1719 Friend 数学推导

题链:http://acm.hdu.edu.cn/showproblem.php?pid=1719 Friend Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2099    Accepted Submission(s): 1058 Problem Description Friend number are defined recur

hdu 5211 Mutiple 数学

Mutiple Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5211 Description wld有一个序列a[1..n], 对于每个1≤i<n, 他希望你求出一个最小的j(以后用记号F(i)表示),满足i<j≤n, 使aj为ai的倍数(即aj mod ai=0),若不存在这样的j,那么此时令F(i) = 0保证1≤n≤10000,1≤ai≤10000 对于任意

HDU 5047 Sawtooth(数学 公式 大数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 Problem Description Think about a plane: ● One straight line can divide a plane into two regions. ● Two lines can divide a plane into at most four regions. ● Three lines can divide a plane into at m

hdu 5073 Galaxy(数学)

题目链接:hdu 5073 Galaxy 题目大意:给定N个点,可以移动其中的K的点,问说最后I的最小值可以是多少. 解题思路:因为质量都为1嘛,所以就是求方差,可以移动K个,所以即选连续的n=N-K个使得方差最小.注意N=K的情 况. S表示n个数的和,T表示n个数平方的和,那么这n个数的方差即为T - S * S / n,然后扫描一遍数组维护S,T,并且计算 方差的最小值. #include <cstdio> #include <cstring> #include <al

HDU 1030 Delta-wave 数学题解

给出一个数字塔,然后求沿着数字之间的边走,给出两个数字,问其路径最短的长度是多少. 看似一条搜索题目,只是有一定做题经验的人都知道,这个不是搜索题,直接搜索肯定超时. 这个是依据规律计算的数学题目. 我这里的思路是一层一层往下搜,利用层间的规律加速,实现层跃,到了同一层,或者同一个对角列的时候就能够直接计算出结果了.对角列即顺着三角形的边能直接走到目标的列. 数学计算出层与层之间相差2,而也能够利用这个规律计算N和M所在的层和列. 这样做由点麻烦,只是我自己琢磨出来的,不错的思路.O(∩_∩)O