zoukankan      html  css  js  c++  java
  • 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 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.

    在一个光滑水平直线轨道上有n个小球。轨道可以被当做一条直线。小球可以被当做质量相同的质点。

     

    最初,小球i在位置Xi。其初速度大小为Vi,速度方向为Di。(Di∈−1,1)

    给定常量C。任意时刻,小球的加速度Ai与速度Vi同方向,并十分玄学地满足等式Ai * Vi = C。

    有多个小球,他们可能在运动过程中发生碰撞。我们假定所有碰撞均为完全弹性碰撞。

     

     

    有多次询问,每次询问有两个整数tk。我们的任务是找出所有小球开始运动t秒后第k小的速度。

     

    * 完全弹性碰撞 : 在碰撞中不损失动能即为完全弹性碰撞。

     

    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

    第一行为一个整数T,表示测试用例的数量。

     

    对于每个测试用例,第一行有两个整数n <= 10^5 与 C <= 10^9。

    随后n行。第i行有三个整数ViXiDiVi表示球i的初速度大小。Xi表示球i的初始位置。Di表示球i的运动方向。

     

    下一行有一个整数q <= 10^5,表示询问的数量。

    随后q行。每行有两个整数 t <= 10^9 与 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 - 输入样例

    Sample Output - 输出样例

    1

    3 7

    3 3 1

    3 10 -1

    2 7 1

    3

    2 3

    1 2

    3 3

    6.083

    4.796

    7.141

     

    【题解】

      加速每一个小球都有一个初始状态,因为A*V=C,所以所有球的当前状态只和初始状态的后t秒有关。

      把题目给的表达式转成和时间t有关的函数。

        A(t) *V(t)  = C

      速度的变化率也就是加速度,即A(t) = V(t)

      带入上面的式子

        V(t)*V(t) =  C

      然后求不定积分,求原函数…………(反正我只会求导所以默默地逆向)

        V(t)*V(t)/2 = Ct

        V(t) = 

      如果有常数什么的话就不管了,反正都能通过移动t来达到相应的速度。

     

      根据动量定理,小球碰撞之后只是交换速度,其实没有什么变化,所以位置和速度方向就不用管了。

      把每个小球的初始速度换算成tt越大速度越快,可以得到小球速度的排名。每次查询时间的增量是固定,因此不影响排名。

    【代码 C++

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cmath>
     4 double data[100005];
     5 int main(){
     6     __int64 T, n, c, v, i, t, k;
     7     char r[10];
     8     scanf("%I64d", &T);
     9     while (T--){
    10         scanf("%I64d%I64d", &n, &c); c <<= 1;
    11         for (i = 1; i <= n; ++i){
    12             scanf("%I64d", &v); gets(r);
    13             data[i] = (double)v*v / c;
    14         }
    15         std::sort(data + 1, data + n + 1);
    16         scanf("%I64d", &n);
    17         while (n--){
    18             scanf("%I64d%I64d", &t, &k);
    19             printf("%.3lf
    ", sqrt(c*(data[k] + t)));
    20         }
    21     }
    22     return 0;
    23 }


     

     

  • 相关阅读:
    解决执行sql脚本报错:没有足够的内存继续执行程序。
    正则表达式学习
    art-template模板引擎循环嵌套
    textarea 设置最长字数和显示剩余字数
    display:table-cell
    js 发送 ajax 是数组 后台循环 发送json 到前台的方法
    js 函数内数据调用
    Angular 原文输出
    Angular 路由跳转
    JQ 按钮实现两种功能
  • 原文地址:https://www.cnblogs.com/Simon-X/p/5797723.html
Copyright © 2011-2022 走看看