Zoj3728_collision (Simple computational geometry)

Source: Internet
Author: User

///////////////////////////////////////////////////////////////////////////////////////////////////////
tt2767
Disclaimer: This document is subject to the following agreement free reprint-non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0
To view the update and discussion of this article, please click here: http://blog.csdn.net/tt2767
Link is deleted please Baidu: CSDN tt2767
///////////////////////////////////////////////////////////////////////////////////////////////////////

Key: This problem to understand after the main set of templates to calculate.
1. Use dot product (dot) to determine if the circle is not
2. The distance from the origin to the straight line is obtained by the cross product.
3. Two situations: rebound or no impact after impact
4. Remember to keep only 3 decimal places

#include <sstream>#include <string>#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <math.h>#include <iterator>#include <map>#include <stack>#include <queue>#include <set>#include <list>#include <functional>#include <numeric>using namespace STD;inline intLowbit (intx) {returnx& (-X);}structpoint{Doublex, y; Point (DoubleXDoubleY): X (x), Y (y) {} point () {}};typedefPoint Vector;DoubleCross (vector A, vector b) {returna.x*b.y-a.y*b.x;}DoubleDot (vector A, vector b) {returnA.X*B.X+A.Y*B.Y;}typedef  Long Long intLL;Const DoubleEPS =1e-9;Const intINF =0x3f3f3f3f;Const Long DoublePI =ACOs(0.0) *2.0;Const intN =100009;intMain () {DoubleRm,r,r,x,y,vx,vy; while(scanf("%LF%LF%LF%LF%LF%LF%LF", &rm,&r,&r,&x,&y,&vx,&vy) = =7) {point P (x, y); Vector S (0-X,0-y), V (vx,vy);        Rm+=r; R+=r;DoubleVel =sqrt(V.X*V.X+V.Y*V.Y);DoubleD =fabs(Cross (S,V))/vel;if(Dot (s,v) < EPS | | d-r > EPS)printf("0.000\n");Else if(D-rm > EPS)printf("%.3lf\n",2*sqrt(r*r-d*d)/vel);Else            printf("%lf\n",2*(sqrt(r*r-d*d)-sqrt(rm*rm-d*d))    /vel); }return 0;}

Copyright NOTICE: This article for Bo Master original article, allow non-commercial reprint, reprint must note name author (CSDN tt2767) and this blog link: http://blog.csdn.net/tt2767.

Zoj3728_collision (Simple computational 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.