zoukankan      html  css  js  c++  java
  • HDU 4793 Collision (2013长沙现场赛,简单计算几何)

    Collision

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 685    Accepted Submission(s): 248
    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 Rm, 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 Rm, R, r, x, y, vx and vy in one line. Here 1 ≤ Rm < 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
     
     
    【题意】:
    圆心在原点的两个同心圆,半径是Rm和R,还有一个半径为r的硬币,给出初始位置和速度矢量,
    硬币与内圆碰撞后会等动能反弹,求硬币在大圆区域内运动的时间。。。
     
    【解题思路】:
    在t时刻,硬币的位置为P(x+Vx*t, y+Vy*t)把P分别代到x^2+y^2=(R+r)^2 和 x^2+y^2=(Rm+r)^2(一定要加 r )中,可以求出硬币与大小圆接触的时间点
    根据方程的解的情况判断:若与大圆无2个交点输出0;若与内圆无2个交点输出t1-t2;
    若发生碰撞,则输出2*(t3-t1); —— 若碰撞,则入射与反射路径对称,长度必然相等
    WA了一次,没有判断方程解的非负性
     
     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #define eps 1e-8    /* >0:>eps--- <0:<-eps */
     7 #define zero(x)(((x)>0?(x):-(x))<eps)
     8 #define PI acos(-1.0)
     9 #define LL long long
    10 #define maxn 100100
    11 #define IN freopen("in.txt","r",stdin);
    12 using namespace std;
    13 
    14 int sign(double x)
    15 {
    16     if(fabs(x)<eps) return 0;
    17     return x<0? -1:1;
    18 }
    19 
    20 double Rm,R,r,x,y,vx,vy;
    21 double v;
    22 
    23 int main(int argc, char const *argv[])
    24 {
    25     //IN;
    26 
    27     while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF)
    28     {
    29         double a,b,c,del;
    30         a = vx*vx+vy*vy;
    31         b = 2.0*x*vx + 2.0*y*vy;
    32         c = x*x + y*y - (R+r)*(R+r);
    33 
    34         del = (b*b - 4.0*a*c);
    35         if(sign(del)<=0) {printf("0
    ");continue;}
    36 
    37         del=sqrt(del);
    38         double t1,t2;
    39         t1 = (-b+del)/(2.0*a);t2 = (-b-del)/(2.0*a);
    40         if(t1>t2) swap(t1,t2);
    41         if(t1<0) {printf("0
    ");continue;}
    42 
    43         a = vx*vx+vy*vy;
    44         b = 2.0*x*vx + 2.0*y*vy;
    45         c = x*x + y*y - (Rm+r)*(Rm+r);
    46 
    47         del = (b*b - 4.0*a*c);
    48         if(sign(del)<=0) {printf("%.3lf
    ",fabs(t1-t2));continue;}
    49 
    50         del=sqrt(del);
    51         double t3,t4;
    52         t3 = (-b+del)/(2.0*a);t4 = (-b-del)/(2.0*a);
    53         if(t3>t4) swap(t3,t4);
    54         if(t3<0) {printf("%.3lf
    ",fabs(t1-t2));continue;}
    55 
    56         printf("%.3lf
    ",2.0*fabs(t3-t1));
    57     }
    58 
    59     return 0;
    60 }
  • 相关阅读:
    GirdView实现折叠式效果
    asp.net MVC出错解决
    C#如何实现从内存中加载程序集
    从线程池看《操作系统》专业课的作用【转自杨中科学生大本营】
    JavaScript的10个非常有用的方法【转】
    JQuery最佳实践:JQuery自定义事件的应用
    C#的委托事件在winform窗体中实现传值备忘
    asp.net异步获取datatable并显示
    ASP.NET 请求处理流程【转】
    温故而知新:WinForm/Silverlight多线程编程中如何更新UI控件的值
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/4926613.html
Copyright © 2011-2022 走看看