Hdu 40,242 min

Source: Internet
Author: User

transferred from: http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html one is calculated directly from the formula, and the other is two-point calculation. Both methods are fast, fully realize the high efficiency of the two points AH ~ ~ ~ a very important condition in the title is (lx*lx+ly*ly) < VD*VD < VB*VB, This means it must be able to catch up, and can be shot at the maximum distance, so the first question must be the answer L. Assuming the Chaser is running at T1, then the bullet flight time is l/vb. so the position of the Chaser at this time is a (x1+ (T1+L/VB) *lx,y1+ (T1+L/VB) *ly). then point (x2,y2) to a distance equal to L+VD*T1 or L-VD*T1//two equations It is easy to solve a single-element two-time equation. There are two equations above, and 4 solutions can be obtained. then choosing the smallest nonnegative solution is the answer. Note that the last time to add L/vb
1 /*2 HDU 40243 find a mathematical formula to calculate4 */5 6#include <stdio.h>7#include <iostream>8#include <math.h>9#include <string.h>Ten using namespacestd; One  A intMain () - { -     //freopen ("d.in", "R", stdin); the     //freopen ("D.out", "w", stdout); -     Doublex1,y1,x2,y2,lx,ly,vd,vb,l; -      while(SCANF ("%LF%LF%LF%LF%LF%LF%LF%LF%LF",&x1,&y1,&x2,&y2,&lx,&ly,&vd,&vb,&L)) -     { +         if(x1==0&&y1==0&&x2==0&&y2==0&&lx==0&&ly==0&&vd==0&&vb==0&&l==0) Break; -         Doublea=vd*vd-lx*lx-ly*Ly; +         Doubleb=2*l*vd-2*lx* (X1-X2+L*LX/VB)-2*ly* (y1-y2+l*ly/VB); A         Doublec=l*l-(X1-X2+L*LX/VB) * (X1-X2+L*LX/VB)-(Y1-Y2+L*LY/VB) * (y1-y2+l*ly/VB); at  -         DoubleS1= (-b-sqrt (b*b-4*A*C))/(2*a); -         DoubleS2= (-b+sqrt (b*b-4*A*C))/(2*a); -  -b=-2*l*vd-2*lx* (X1-X2+L*LX/VB)-2*ly* (y1-y2+l*ly/VB); -         DoubleS3= (-b-sqrt (b*b-4*A*C))/(2*a); in         DoubleS4= (-b+sqrt (b*b-4*A*C))/(2*a); -  toprintf"%.3LF", L); + //Select a minimum positive number from the S1 S2 S3 S4 -         if(s1<0) s1=10000000000.0; the         if(s2<0) s2=10000000000.0; *         if(s3<0) s3=10000000000.0; $         if(s4<0) s4=10000000000.0;Panax Notoginsengprintf"%.3lf\n", Min (S1,min (S2,min (S3,S4))) +l/vb);//don't forget to add l/vb -     } the     return 0; +}

1 /*2 HDU 40243 two points4 */5#include <stdio.h>6#include <iostream>7#include <math.h>8#include <algorithm>9 using namespacestd;Ten Const Doubleeps=1e-8;//1e-6 will WR One Const Doubleinf=1e9; A intMain () - { -     //freopen ("d.in", "R", stdin); the     //freopen ("D.out", "w", stdout); -     Doublex1,y1,x2,y2,lx,ly,vd,vb,l; -      while(SCANF ("%LF%LF%LF%LF%LF%LF%LF%LF%LF",&x1,&y1,&x2,&y2,&lx,&ly,&vd,&vb,&L)) -     { +         if(x1==0&&y1==0&&x2==0&&y2==0&&lx==0&&ly==0&&vd==0&&vb==0&&l==0) Break; -         DoubleL=0; +         DoubleR=INF; A         Doublemid; at         Doublex, y; -          while(l<r-EPS) -         { -Mid= (L+R)/2; -x=x1+mid*Lx; -y=y1+mid*Ly; in             DoubleD=sqrt ((x-x2) * (X-X2) + (y-y2) * (Y-y2));//two point distance -             Doubled1=vd* (MID-L/VB);//the maximum distance a warrior runs to             if(d<=l)//inside the Circle parallel relations +             { -                 if(d+d1<=l) L=mid;//I can't get to the circumference. the                 ElseR=mid; *             } $             ElsePanax Notoginseng             { -                 if(L+d1<=d) L=mid;//I can't get to the circumference. the                 ElseR=mid; +             } A         } theprintf"%.3LF%.3lf\n", l,mid); +     } -     return 0; $}

Hdu 40,242 min

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.