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 }