路径导航
Problem:2141
Time Limit:1000ms
Memory Limit:65535K
Description
从学校出发去乐松广场,百度地图导航路径为经过北门,直行右转,过路后到达目的地,或者经过东门,直行左转到达目的地。现请按最短距离原则给出最终选择路径。为表述方便,起点为点A,北门为点B,东门为点C,乐松广场为点D。
输入数据有多组,每组为ABCD 4个点的坐标,输出所选择的路径,每个点之间用1个空格分隔,每组数据单独1行输出;备注:常用的数学函数在<math.h>文件中。
Input
Output
Sample Input
1 1 2 4 4 1 5 2
1 1 1.5 5 3.2 1 5.5 2.1
Sample Output
A C D
A C D
Hint
Source
#include <bits/stdc++.h>
using namespace std;
struct student
{
double x,y;
};
int f(int a,int b,int c,int d)
{
double s=0;
s=(c-a)*(c-a)+(d-b)*(d-b);
return s;
}
int main()
{
double A,B,C,D;
student stu[10000];
while(cin>>stu[1].x>>stu[1].y)
{
for(int i=2;i<=4;i++)
{
cin>>stu[i].x>>stu[i].y;
}
if((f(stu[1].x,stu[1].y,stu[2].x,stu[2].y)+f(stu[2].x,stu[2].y,stu[4].x,stu[4].y))<(f(stu[1].x,stu[1].y,stu[3].x,stu[3].y)+f(stu[3].x,stu[3].y,stu[4].x,stu[4].y)))
{
cout<<"A B D"<<endl;
}
else
cout<<"A C D"<<endl;
}
return 0;
}
2475

被折叠的 条评论
为什么被折叠?



