HDU 4793 Collision (2013 Changsha Regional Race game c)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4793

Problem-Solving report: There is a circular medal on a plane, the radius is Rm, the center of the Circle is (0,0), and there is a circle range center is also (0,0), the radius is r,r > Rm, now throws a coin to the plane, the initial center position of the coin is (x, y), the radius is R, Give the speed of the coin vector, the coin will be reflected when the medal, note that the reflection is the original way back, not according to the common sense of the line in accordance with the route of the center, said always thought it was so, WA for a long time, then, let you ask the coin and the circle of the intersection of the total time is how much.

First, pass the origin, make a line l parallel to the velocity vector, and then find the distance d (x, y) to the line L, and then pass a series of Pythagorean theorem to find out the way. It is worth noting that there are several cases to be awarded.

First, the direction of the velocity with (x, Y) and the origin of the line of the vector angle is not the range of [0,90], and then after satisfying this condition also to judge, when D > R+r, the coin will be directly past without a circular range, so the time is directly 0, when Rm+r < D < R+r, Coins go through a circular range, but do not collide with medal, and when D < rm+r, coins collide with medal.

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Const DoubleEPS = 1e-8, PI = ACOs (-1.0);8 9 struct PointTen { One     Doublex, y; APointDoublex =0,Doubley =0): X (x), Y (y) {} -     DoubleLen () -     { the         returnsqrt (x*x+y*y+EPS); -     } - }; -InlineDoubledis (point p1,point p2) + { -     returnsqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (P1.Y-P2.Y) +EPS); + } A DoubleGet_dis (Point v,point p) at { -     if(Fabs (V.X*P.Y-P.X*V.Y) < EPS)return 0; -     DoubleSi = (v.x*p.y-p.x*v.y)/dis (Point (0,0), V)/P.len (); -     returnP.len () *fabs (SI); - } - intjudge (Point P,point v) in { - Point temp; totemp.x =-1*p.x; +TEMP.Y =-1*p.y; -     return(Temp.x*v.x+temp.y*v.y <0) || (Fabs (TEMP.X*V.X+TEMP.Y*V.Y) <EPS); the } * intMain () $ {Panax Notoginseng //freopen ("In.txt", "R", stdin); -     DoubleRm,r,r; the Point p,v; +      while(SCANF ("%LF%LF%LF%LF%LF%LF%LF", &rm,&r,&r,&p.x,&p.y,&v.x,&v.y)! =EOF) A     { the         if(judge (p,v)) +         { -printf"0.0000\n"); $             Continue; $         } -         DoubleV =V.len (); -         DoubleD = Get_dis (v,p);//get the distance from the movement of the coin to the Origin . the //printf ("%.3lf\n", D); -         DoubleAns =0;Wuyi         if(D < Rm+r)//would collide, pits, in which case the reflection of the subject was contrary to common sense, and has been WA here the         { -             DoubleL = sqrt ((r+r) * (r+r)-d*d+eps)-sqrt ((rm+r) * (rm+r)-d*d+eps);//the distance from the beginning of the circle to the collision WuAns + = (L/V); -         //ans + = (r-rm)/V; About         } $         Else if(d > Rm+r && D < r +R) -         { -             Doublet = sqrt ((r+r) * (r+r)-d*d+eps)/V; -         } A         Else     //does not enter a circular range +         { theprintf"0.00000\n"); -             Continue; $         }  theprintf"%lf\n",2*ans+EPS); the     } the     return 0; the}
View Code

HDU 4793 Collision (2013 Changsha Regional Race game c)

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.