Binary and trigger

Source: Internet
Author: User

 

Binary and trigger

(I forgot to publish it very early...) today, the senior students of the second year of senior high school conducted a test of two or three points (also known as the one-pass after-school question test). I feel this is very interesting ~

Regarding what is binary or trigger, I first cool to see a question.

Bulbs: https://loj.ac/problem/10016

  

Question Overview: give $ H, H, d $, and find the maximum length of the Shadow (including the top of the ground and the top of the wall ).

There is a sense of sight in junior high school mathematics.

Solution: Set the light bulb to $ A $, and the head to $ B $. Connect to $ AB $ and extend the light bulb. The extension line with the ground is handed over to the point $ C $.

  

  

  

So it's over?

Another possibility is that the shadow does not go to the wall, but it does not have much influence. The two functions are still single-peak, and it seems like the check function?

  
 1 # include <cstdio> 2 # include <iostream> 3  4 using namespace std; 5  6 int T; 7 double H,h,d,a1,a2; 8 double ans,l,r,lmid,rmid; 9 10 double f (double x)11 {12     double ans=0,a,b;13     b=h*(d-x)/(H-h);14     if(b<=x)15         return b;16     ans+=x;17     a=(x*H-d*h)/(h-H);18     ans+=a*h/(x+a);19     return ans;20 }21 22 int main()23 {24     scanf("%d",&T);25     while (T--)26     {27         scanf("%lf%lf%lf",&H,&h,&d);28         l=0,r=d,ans=0;29         while (r-l>=0.0001)30         {31             lmid=l+(r-l)/3.0;32             rmid=r-(r-l)/3.0;33             a1=f(lmid);34             a2=f(rmid);35             if(f(lmid)<f(rmid))36                 l=lmid;37             else 38                 r=rmid;39         }40         printf("%.3lf\n",f(l));41     }42     return 0;43 }
Light bulb

 

Windward Dance: https://www.cnblogs.com/shzr/p/9751719.html

 

Conveyor Belt: https://www.luogu.org/problemnew/show/P2571

Question Overview: given the two line segments on the plane, the moving speed of each line is $ A $, $ B $, and can also be separated from the line segment to the plane, there is also a speed of $ C $. Calculate the shortest distance from $ A $ on the first line segment to $ d $ on the other.

The first thing that comes to mind is greed... if the plane goes fast, it goes on the plane. If the online is faster, it goes online. However, this is obviously wrong, because sometimes, although the online is faster, but is it more and more biased?

The final answer should be to walk a segment on the starting line segment, then walk a segment on the plane to reach the end line segment, and then go to the end line segment. consider a simple question first. If there is only one line segment on the plane, how can we find the minimum distance from a point to the end of the line segment? The column equation is found to be a quadratic function. You can find the coefficient to obtain the extreme value or three points. the starting point is not fixed: if the minimum distance is obtained for each starting point, it can be regarded as a function about the starting point. first, this function should be continuous, so if you want to understand the simulated annealing, it is obviously not necessarily monotonous, but it should not be a particularly strange shape, I can't prove it rigorously, but I can feel it. the optimal solution must exist, and the more the starting point deviates from the optimal solution, the worse the answer. why? The following is a random proof, which is not guaranteed to be correct: the starting point moves a little bit, and the arrival point moves accordingly. In a very small range, this movement may be monotonous, but after a certain point, it will move in the opposite direction?

  

In short, there is no good proof on the Internet.

Note: It is possible that a line segment degrades to a point and exits after three points have not started... you can switch to the three-point control method.

  
 1 # include <cstdio> 2 # include <iostream> 3 # include <cmath> 4 # include <algorithm> 5  6 using namespace std; 7  8 const int maxn=300; 9 int ax,ay,bx,by;10 int cx,cy,dx,dy;11 double p,q,r;12 double la,lb,L,R,lmid,rmid;13 int cnt=maxn;14 15 inline double l (double len,double x,double y)16 {17     double ans=0,x_,y_;18     x_=cx,y_=cy;19     if(lb) x_=len*(dx-cx)/lb+cx;20     if(lb) y_=len*(dy-cy)/lb+cy;21     ans+=sqrt((x_-dx)*(x_-dx)+(y_-dy)*(y_-dy))/q;22     ans+=sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_))/r;23     return ans;    24 }25 26 inline double f (double len)27 {28     double L=0,R=lb,lmid,rmid,x,y,l1;29     x=ax,y=ay;30     if(la) x=len*(bx-ax)/la+ax;31     if(la) y=len*(by-ay)/la+ay;32     l1=sqrt((x-ax)*(x-ax)+(y-ay)*(y-ay))/p;33     int cnt=maxn;34     while (cnt)35     {36         lmid=L+(R-L)/3.0;37         rmid=R-(R-L)/3.0;38         if(l(lmid,x,y)>l(rmid,x,y))39             L=lmid;40         else R=rmid;41         cnt--;42     }43     return l(L,x,y)+l1;44 }45 46 int main()47 {48     scanf("%d%d%d%d",&ax,&ay,&bx,&by);49     scanf("%d%d%d%d",&cx,&cy,&dx,&dy);50     scanf("%lf%lf%lf",&p,&q,&r);51     la=sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));52     lb=sqrt((cx-dx)*(cx-dx)+(cy-dy)*(cy-dy));53     L=0,R=la;54     while (cnt)55     {56         lmid=L+(R-L)/3.0;57         rmid=R-(R-L)/3.0;58         if(f(lmid)>f(rmid))59             L=lmid;60         else R=rmid;61         cnt--;62     }63     printf("%.2lf",f(R));64     return 0;65 }
Conveyor Belt

--- Shzr

Binary and trigger

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.