HDU 4793 Collision

Collision

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 459    Accepted Submission(s): 180
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


题意:有一个圆环......圆环外面有一个小圆C,一开始知道C的速度的向量,C如果碰到圆环的内圆,会反弹,假设不会损失能量,问C有多长时间在圆环的外圆和内圆之间。


思路:直接乱搞一下就好了吧。 先判断会不会与圆环的外圆相交,如果相交,再判断是否会与内圆相交。如果不与内圆相交,直接求出第一次与外圆相切的时间和第二次相切的时间就行了。 如果与内圆相交求出第一次与内圆相切的时间就行了,最后是这个时间的两倍,因为整个过程是对称的。


代码:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <stdio.h>
#include <cmath>
#include <math.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,b,a) for(int i = (b); i >= (a); --i)
#define clr(a,x) memset(a,(x),sizeof(a))
#define LL long long
#define eps 1e-8
using namespace std;
const double PI = 4.0 * atan(1.0);

struct Point
{
    double x,y;
    Point (double x=0,double y=0)
    :x(x),y(y) { }
};

int dcmp(double a,double b)
{
    if (a < b - eps) return -1;
    else if (a > b + eps) return 1;
    else return 0;
}

void input()
{
}

inline double sqr(double x) { return x * x; }

Point operator - (const Point & a,const Point & b)
{
    return Point(a.x-b.x,a.y-b.y);
}

inline double Dot(Point a,Point b) { return a.x * b.x + a.y * b.y ; }
inline double Length(Point a) { return sqrt(Dot(a,a)); }
inline double Len2(Point a) { return Dot(a,a); }
inline double Length(Point a,Point b) { return Length(a-b); }


inline double Angel(Point a,Point b)
{
    double X = (Len2(a) + Len2(b) - Len2(a-b)) / 2 / Length(a) / Length(b);
    return acos(X);
}

bool solve()
{
    double Rm,R,r,x0,y0,vx,vy;
    if (scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x0,&y0,&vx,&vy) != 7) return false;
    double A = vy, B = -vx , C = vx * y0 - vy * x0;
    double distToCenter = abs(C) / sqrt(A*A + B*B);
    Point center = Point(0,0); Point Ap = Point(x0,y0);
    double angel = Angel(Point(vx,vy),center-Ap);
    double cosA = cos(angel);
    double AC = Length(Ap-center);
    A = 1; B = -2.0 * AC * cosA; C = sqr(AC) - sqr(R+r);
    double delta = sqr(B) - 4.0 * A * C;
    if (dcmp(delta,0) <= 0 ||
         dcmp(distToCenter-r,R) >= 0 ||
          dcmp(angel,PI * 0.5) >= 0) {
        puts("0.000");
        return true;
    }

    delta = sqrt(delta);
    double d1 = (-B - delta) / 2, d2 = (-B + delta) / 2;
    double v = Length(Point(vx,vy));
    if (dcmp(distToCenter-r,Rm) >= 0) {
        double t = (d2 - d1) / v;
        printf("%.5lf\n",t);
        return true;
    }
    A = 1; B = -2.0 * AC * cosA; C = sqr(AC) - sqr(Rm+r);
    delta = sqrt(sqr(B) - 4.0 * A * C);
    double dm1 = (-B - delta) / 2;
    double t = (dm1 - d1) / v * 2;
    printf("%.5lf\n",t);
    return true;
}

int main()
{
    #ifdef ACM
        freopen("in.txt", "r", stdin);
    #endif // ACM
    while (solve()) {
       // input();
    }
}





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值