hdu5826 physics(物理推公式)

本文介绍了一种解决多个小球在光滑水平直轨上碰撞的问题的方法。通过使用C语言编程,实现对小球初始速度、位置及方向的输入,并在设定时间内计算出指定排序下小球的速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思路:这个题我的推导过程是vt^2-vo^2=2as, s=vt,c=av然后代一下就出来了...并没有积分..不过效果是一样的


#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 100005;
struct node
{
    double v, x, d;
}que[N];
bool cmp(node a, node b)
{
    return a.v < b.v;
}

int main()
{
    int t, n, m;
    double c;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d%lf", &n, &c);
        for (int i = 0; i < n; i++)
            scanf("%lf%lf%lf", &que[i].v, &que[i].x, &que[i].d);
        sort(que, que + n, cmp);

        scanf("%d", &m);
        double t;
        int k;
        for (int i = 0; i < m; i++)
        {
            scanf("%lf%d", &t, &k);
            double tv = sqrt(2.0*c*t + que[k - 1].v*que[k - 1].v);
            printf("%.3lf\n", tv);
        }
    }
    return 0;
}


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
 

Author
学军中学


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值