zoj 3728 Collision(2013亚洲区域赛 长沙站 C)


http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5074

Collision

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

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 Rm, radius of coin r, radius of the round range R, initial position (xy) and initial speed vector (vxvy) 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.



思路:题意很容易理解就直接说思路了,我是解方程算的,设过t时间硬币进入R区域,那么有

x'=x+t*vx

y'=y+t*vy

带入到方程: (x')^2+(y')^2<=(R+r)^2,解出t1,t2,只有当t1!=t2且t1,t2均大于0时才表示硬币进入到了R,否则直接输出0即可(无解或只有一解或有解小于0),然后用相同的方法判断硬币是否进入Rm,如果没有碰到,则|t1-t2|就是答案,否则计算出硬币碰到Rm的时间t3,设t1>t2,那么2*(t3-t2)即为答案(因为硬币碰到Rm后做反射运动)。

代码如下:


#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#define maxn 100100
using namespace std;
double Rm,R,r,x,y,vx,vy;
int main()
{
  //  freopen("dd.txt","r",stdin);
    while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
    {
        double a=vx*vx+vy*vy;
        double b=2*(vx*x+vy*y);
        double c=x*x+y*y-(R+r)*(R+r);
        double deta=b*b-4*a*c;
        if(deta<=0||a==0)
        {
            printf("0.000\n");
            continue;
        }
        double t1=(-b+sqrt(deta))/(2*a),t2=(-b-sqrt(deta))/(2*a);
        if(t2>=0)//和R有交点
        {
            c=x*x+y*y-(Rm+r)*(Rm+r);
            double deta1=b*b-4*a*c;
            double time;
            if(deta1<=0)//没有碰到medal
            {
                 time=t1-t2;
            }
            else
            {
                double t3=(-b-sqrt(deta1))/(2*a);
                time=2*(t3-t2);
            }
            printf("%.3lf\n",time);
        }
        else
        {
            printf("0.000\n");
        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值