Three points of quality in hdu-3400

Source: Internet
Author: User

Question Link

Well, there is a quality three-point question, which belongs to the nested three-point question.

After thinking about this question for a long time, I only wrote several independent equations. Let's look at the solution report. Then, I began to think about how to use the three-way method. I have never been able to figure it out (under review, there is no independent analysis ).

Look at Daniel's problem-solving report to find out how to do it;

Well written. Http://hi.baidu.com/1093782566/blog/item/2bb8a017124a3735dd540126.html

Here we will mainly explain how three points are made.

Total time consumed T = x/P + Y/R + z/Q;
X = SQRT (XX-Ax) ^ 2 + (xy-ay) ^ 2), monotonic incrementing Function
Y = SQRT (-Yx + dx) ^ 2 + (dy-yy) ^ 2), monotonic decreasing function
Z = SQRT (Yx-xx) ^ 2 + (yy-XY) ^ 2) convex function.

Because Z is determined by X and Y, Z is increased first and then subtracted. First 3 X, then 3 Y. X is related to X (A, B) and Y (c, d. That is, you can nest the three-point search y based on the three-point search X.

Code:

#include<iostream>#include <math.h>#include <stdio.h>using namespace std;#define INF 0.00001class point{public:double x;double y;};point A,B,C,D;double P,R,Q;double cal_dis(point a,point b){return sqrt((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x));}double cal_y(point a){point first=C;point end=D;point mid,midmid;double t1,t2;do{mid.x=(first.x+end.x)/2.0;mid.y=(first.y+end.y)/2.0;midmid.x=(mid.x+end.x)/2.0;midmid.y=(mid.y+end.y)/2.0;t1=cal_dis(mid,D)/Q+cal_dis(a,mid)/R;t2=cal_dis(midmid,D)/Q+cal_dis(a,midmid)/R;if(t1>t2) first=mid;else end=midmid;}while(fabs(t1-t2)>INF);return t1;}double cal_t(){point first=A;point end=B;point mid,midmid;double t1,t2;do{mid.x=(first.x+end.x)/2.0;mid.y=(first.y+end.y)/2.0;midmid.x=(mid.x+end.x)/2.0;midmid.y=(mid.y+end.y)/2.0;t1=cal_dis(mid,A)/P+cal_y(mid);t2=cal_dis(midmid,A)/P+cal_y(midmid);if(t1>t2) first=mid;else end=midmid;}while(fabs(t1-t2)>INF);return t1; }int main(){int t;cin>>t;while(t--){cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y>>P>>Q>>R;printf("%.2lf\n",cal_t());}return 0;}

Recent mood fluctuations are large. Come on !!! Awkward ~~~~ Believe that you can !!!!

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.