hdu2671

Can't be easier

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 796    Accepted Submission(s): 364


Problem 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.
 

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 ).
 

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

AC代码:

#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() {         int c;         double k,x1,y1,x2,y2,x3,y3,x,y,dis,t,a,b;         cin>>c;         while(c--)         {                 cin>>k>>x1>>y1>>x2>>y2>>x3>>y3;                 if(x3!=1.0)                         t=k-k*x3+y3; //用直线上的(1,t)和(x3,y3)表示这条直线L                 else                         t=2*k-k*x3+y3;  //用直线上的(2,t)和(x3,y3)表示这条直线L                 a=(1-x3)*(y2-y3)-(t-y3)*(x2-x3);                 b=(1-x3)*(y1-y3)-(t-y3)*(x1-x3);                 if(a*b>0) //a,b为AC,BC两直线和直线L的叉积,异号则在直线异侧                 {                         y=(2*y3+(k*k-1)*y2+2*k*(x2-x3))/(k*k+1); //联立向量(CA+CB)所在直线的斜率为k和向量AB所在直线的斜率为-1/k两个方程解得B`                         x=x2-k*(y-y2);                         dis=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));                 }                 else                         dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));                 printf("%.2lf\n",dis);         }         return 0; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值