zoukankan      html  css  js  c++  java
  • hdu 5826 physics 物理题

    physics

    题目连接:

    http://acm.hdu.edu.cn/showproblem.php?pid=5826

    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

    Hint

    题意

    给你n个球,以及球的位置,球初始方向,球保证都在x轴上。

    而且V[i]*A[i] = C

    现在有Q次询问,问你在第t秒,第k大的速度是多少。

    题解:

    弹性碰撞,那么其实就是交换速度,那么就和位置无关了。

    第k大,其实就是开始速度第k大的球。

    速度怎么求呢? V[i]*A[i] = C ,那么 Cdt = V[i]dV,然后积分 2k+2Ct = V[i]^2,把初速度带进去,把k解出来就好了。

    (其实功率是守恒的,用这个做也很简单

    代码

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int V[100010];
    int n,c,t,k,q,T;
    
    double solve(int v,int t)
    {
        return (sqrt(1.0*v*v+2.0*t*c));
    }
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&c);
            for(int i=1;i<=n;i++)
            {
                int v,x,d;
                scanf("%d%d%d",&v,&x,&d);
                V[i]=v;
            }
            sort(V+1,V+1+n);
            scanf("%d",&q);
            while(q--)
            {
                scanf("%d%d",&t,&k);
                printf("%.3f
    ",solve(V[k],t));
            }
        }
        return 0;
    }
  • 相关阅读:
    BZOJ 2956: 模积和
    BZOJ 1113: [Poi2008]海报PLA
    停课刷题总结-给自己一点鼓励吧
    BZOJ 2751: [HAOI2012]容易题(easy)
    Vijos 1100 加分二叉树
    BZOJ 1756: Vijos1083 小白逛公园
    BZOJ 1709: [Usaco2007 Oct]Super Paintball超级弹珠
    BZOJ 1652: [Usaco2006 Feb]Treats for the Cows
    BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
    BZOJ 1631: [Usaco2007 Feb]Cow Party
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5763104.html
Copyright © 2011-2022 走看看