hdu-4793-Collision

Collision

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 822    Accepted Submission(s): 308
Special Judge

Problem Description
There's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact the same center as the round medal, and radius of the medal is strictly less than radius of the round range. Since that the round medal is fixed and the coin is a piece of solid metal, we can assume that energy of the coin will not lose, the coin will collide and then moving as reflect.
Now assume that the center of the round medal and the round range is origin ( Namely (0, 0) ) and the coin's initial position is strictly outside the round range.
Given radius of the medal R m, radius of coin r, radius of the round range R, initial position (x, y) and initial speed vector (vx, vy) of the coin, please calculate the total time that any part of the coin is inside the round range. Please note that the coin might not even touch the medal or slip through the round range.
 

Input
There will be several test cases. Each test case contains 7 integers R m, R, r, x, y, vx and vy in one line. Here 1 ≤ R m < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(x, y)| ≤ 20000, 1 ≤ |(vx, vy)| ≤ 100.
 

Output
For each test case, please calculate the total time that any part of the coin is inside the round range. Please output the time in one line, an absolute error not more than 1e -3 is acceptable.
 

Sample Input
  
  
5 20 1 0 100 0 -1 5 20 1 30 15 -1 0
 

Sample Output
  
  
30.000 29.394
 

Source
2013 Asia Changsha Regional Contest

我们求时间的话,有两种情况时间始终为0.00,1是当不考虑碰撞时的运动轨迹是一条射线,射线所在直线距离原点的最短距离超过coin和region半径之和,2是本来coin就是越走越远,不可能进入圆环区域region
进入情况下,我们画出图即可写出表达式
我奇怪的一点是为什么读入以int读入就会WA

我们想如果是离原点越来越远的话,必然不会闯到区域region中来,也就是我们取一个最小的位移点,它必然距离会变大
除此之外我们考虑三种情况,coin距离原点的最短距离记为min_distance
1,最短距离大于R+r时,不会进入圆形区域
2,当最短距离小于R+r,而且小于Rm+r,此时不会发生碰撞
3,进入区域并发生碰撞 min_distance < R + r 并且 min_distance < Rm + r

Code
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double Rm,R,r,x,y,vx,vy;
double min_distance,speed,min_distance_2;
int main()
{
    while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy) != EOF)/**/
    {
        if(x * x + y * y < (x + vx * 0.001) * (x + vx * 0.001) + (y + vy * 0.001) * (y + vy * 0.001))
        {
            puts("0.000");
            continue;
        }
        speed = sqrt(vx * vx + vy * vy);
        min_distance_2 = (vx * y - vy * x) * (vx * y - vy * x) / (double)(vx * vx + vy * vy);
        min_distance = sqrt(min_distance_2);
        if(min_distance >= R + r)
        {
            puts("0.000");
            continue;
        }
        if(min_distance > r + Rm)
        {
            printf("%.3f\n",2 * sqrt((R + r) * (R + r) - min_distance_2) / speed);
            continue;
        }
        printf("%.3f\n",2 * (sqrt((R + r) * (R + r) - min_distance_2) - sqrt((Rm + r) * (Rm + r) - min_distance_2))  / speed);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值