Description
I'm sure this problem will fit you as long as you didn't sleep in your High School Math classes.
Yes,it just need a little math knowledge and I know girls are always smarter than we expeted.
So don't hesitate any more,come and AC it!
Tell you three point A,B,C in a 2-D plain,then a line L with a slope K pass through C,you are going to find
a point P on L,that makes |AP| + |PB| minimal.
Yes,it just need a little math knowledge and I know girls are always smarter than we expeted.
So don't hesitate any more,come and AC it!
Tell you three point A,B,C in a 2-D plain,then a line L with a slope K pass through C,you are going to find
a point P on L,that makes |AP| + |PB| minimal.
Input
The first line contain a t.
Then t cases followed,each case has two parts,the first part is a real number K,indicating the slope,and the second
part are three pairs of integers Ax,Ay,Bx,By,Cx,Cy(0 <=|Ax|,|Ay|,|Bx|,|By|,|Cx|,|Cy| <= 10000 ).
Then t cases followed,each case has two parts,the first part is a real number K,indicating the slope,and the second
part are three pairs of integers Ax,Ay,Bx,By,Cx,Cy(0 <=|Ax|,|Ay|,|Bx|,|By|,|Cx|,|Cy| <= 10000 ).
Output
Just out put the minimal |AP| + |PB|(accurate to two places of decimals ).
Sample Input
1 2.55 8467 6334 6500 9169 5724 1478
Sample Output
3450.55
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 2009
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int main()
{
ll t,i,j;
while(scanf("%d",&t)==1)
{
for(j=1;j<=t;j++)
{
int flag ;
double k,k1,ax,ay,bx,by,cx,cy,dx,dy,len,re,A,B,C;
scanf("%lf",&k);
scanf("%lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy);
if(k==0)
{
if((ay-cy)*(by-cy)<=0)
flag = 1;
else flag = 0;
}
else
{
if((by- (k*(bx-cx)+cy)) * (ay-(k*(ax-cx)+cy)) <=0)
flag = 1;
else flag = 0;
}
//printf("flag %d\n",flag);
if(flag)
{
printf("%.2lf\n",sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by)));
continue;
}
if(k == 0)
{
dx = bx;
dy = cy*2-by;
}
else
{
/*k1 = -1/k;
mx = (cy-by+k1*bx-k*cx)/(k1-k);
my = k*(mx-cx)+cy;
// printf("mx=%lf my=%lf\n",mx,my);
len = (mx-bx)*(mx-bx)+(my-by)*(my-by);
dx = sqrt((4*len)/(k1*k1+1))+bx;
if(dx==bx)
dx = bx-sqrt((4*len)/(k1*k1+1));
dy = k1*(dx-bx)+by;*/
A = -k;
B = 1;
C = k*cx-cy;
dx = bx - 2*A*(A*bx+B*by+C)/(A*A+B*B);
dy = by - 2*B*(A*bx+B*by+C)/(A*A+B*B);
//dx = ((1-k*k)*ax+2*k*ay-2*k*(cy-k*cx))/(1+k*k);
//dy = ((k*k-1)*ay+2*k*ax+2*(cy-k*cx))/(1+k*k);
}
//printf("%.2Lf",len);
// printf("dx=%lf dy=%lf\n",dx,dy);
re = sqrt((dx-ax)*(dx-ax)+(dy-ay)*(dy-ay));
printf("%.2lf\n",re);
}
}
return 0;
}