HDU 4793 Collision (2013 Changsha Field race, simple calculation geometry)

Source: Internet
Author: User

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 Descriptionthere ' A round medal fixed on an ideal smooth table, Fancy are 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 are strictly less than radius of the round range. Since that the round medal are fixed and the coin is a piece of solid metal, we can assume this energy of the coin would not Lose, the coin would collide and then moving as reflect.
Now assume the center of the Round Medal and the round Range are Origin (Namely (0, 0)) and the coin ' s initial posit Ion 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 VEC Tor (VX, vy) of the coin, please calculate the total time, which any part of the coin is inside the round range. Please note this coin might not even touch the medal or slip through the round range.

Inputthere'll be several test cases. Each test case contains 7 integers Rm, R, R, X, y, VX and VY on one line. Here 1≤rm < r≤2000, 1≤r≤1000, R + R < | (x, y) | ≤20000, 1≤| (VX, VY) | ≤100.

Outputfor Each test case, please calculate the total time, the all part of the coin is inside the round range. Please output the time on one line, an absolute error isn't more than 1e-3 is acceptable.

Sample Input5 20 1 0 100 0-15 20 1 30 15-1 0

Sample Output30.00029.394

Source2013 Asia Changsha Regional Contest "test instructions": Two concentric circles at the origin of the center, with a radius of RM and R, and a coin with a radius of R, giving the initial position and velocity vector, the coin and the inner circle after the collision will wait for kinetic energy rebound, Find the time the coin is moving in the big circle ... "Problem-solving ideas": at t moment, the position of the coin is P (x+vx*t, y+vy*t) to the p respectively to x^2+y^2= (R+r) ^2 and x^2+y^2= (rm+r) ^2 (must add R), It can be found that the time point of contact between the coin and the size circle is judged according to the solution of the equation: if there is no 2 intersection with the great circle output 0, if there is no 2 intersection with the inner circle output t1-t2, if there is a collision, the output of t3-t1; --If the collision, then the incident and reflection path symmetry, the length must be equal to WA once, there is no judgement of the non-negative equation solution
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 #defineEPS 1e-8/* >0:>eps---<0:<-eps */7 #defineZero (x) (((x) >0? ( x):-(x)) <eps)8 #definePI ACOs (-1.0)9 #defineLL Long LongTen #defineMAXN 100100 One #defineIn Freopen ("In.txt", "R", stdin); A using namespacestd; -  - intSignDoublex) the { -     if(Fabs (x) <eps)return 0; -     returnx<0? -1:1; - } +  - DoubleRm,r,r,x,y,vx,vy; + Doublev; A  at intMainintargcChar Const*argv[]) - { -     //in ; -  -      while(SCANF ("%LF%LF%LF%LF%LF%LF%LF", &rm,&r,&r,&x,&y,&vx,&vy)! =EOF) -     { in         DoubleA,b,c,del; -A = vx*vx+vy*vy; tob =2.0*X*VX +2.0*y*vy; +c = x*x + Y*y-(r+r) * (r+R); -  thedel = (B*b-4.0*a*c); *         if(DEL) <=0) {printf ("0\n");Continue;} $ Panax NotoginsengDel=sqrt (del); -         Doublet1,t2; theT1 = (-b+del)/(2.0*a); t2 = (-b-del)/(2.0*a); +         if(t1>T2) Swap (T1,T2); A         if(t1<0) {printf ("0\n");Continue;} the  +A = vx*vx+vy*vy; -b =2.0*X*VX +2.0*y*vy; $c = x*x + Y*y-(rm+r) * (rm+R); $  -del = (B*b-4.0*a*c); -         if(DEL) <=0) {printf ("%.3lf\n", Fabs (T1-T2));Continue;} the  -Del=sqrt (del);Wuyi         DoubleT3,t4; theT3 = (-b+del)/(2.0*a); t4 = (-b-del)/(2.0*a); -         if(t3>T4) swap (T3,T4); Wu         if(t3<0) {printf ("%.3lf\n", Fabs (T1-T2));Continue;} -  Aboutprintf"%.3lf\n",2.0*fabs (t3-t1)); $     } -  -     return 0; -}

HDU 4793 Collision (2013 Changsha Field race, simple calculation geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.