牛客网 牛客小白月赛2 B.小马过河-简单的计算几何

 

B.小马过河

链接:https://www.nowcoder.com/acm/contest/86/B

这个题是一个简单的几何题???套个板子就过了,就是直线上两点确定的这条直线和直线外一点的垂足的坐标。

板子题,但是板子具体的操作没仔细看(嘤嘤嘤???(怕是要被锤死。。。))

板子来源:传送门

 

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<stack>
10 using namespace std;
11 typedef long long ll;
12 const int maxn=1e5+10;
13 const double eps=1e-7;
14 // 二维空间点到直线的垂足
15 struct Point
16 { 17 double x,y; 18 }; 19 Point GetFootOfPerpendicular(const Point &pt,const Point &begin,const Point &end){ 20  Point retVal; 21 double dx = begin.x - end.x; 22 double dy = begin.y - end.y; 23 if(abs(dx) < 0.0000000001 && abs(dy) < 0.0000000001 ){ 24 retVal = begin; 25 return retVal; 26  } 27 double u = (pt.x - begin.x)*(begin.x - end.x) + (pt.y - begin.y)*(begin.y - end.y); 28 u = u/((dx*dx)+(dy*dy)); 29 retVal.x = begin.x + u*dx; 30 retVal.y = begin.y + u*dy; 31 return retVal; 32 } 33 int main(){ 34 int t; 35 cin>>t; 36 while(t--){ 37  Point pt,begin,end; 38 cin>>pt.x>>pt.y>>begin.x>>begin.y>>end.x>>end.y; 39 Point retVal=GetFootOfPerpendicular(pt,begin,end); 40 printf("%.7f %.7f\n",retVal.x,retVal.y); 41  } 42 }

 

转载于:https://www.cnblogs.com/ZERO-/p/9729048.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值