文章
11
粉丝
414
获赞
9
访问
109.2k
//T和Y的计划
#include<iostream>
#include<iomanip>
#include<cmath>
#include <cfloat>
using namespace std;
#define max 5005
typedef struct
{
double x, y, z;
}pos;
pos p[max];
int main()
{
int n;
cin >> n;
pos acm, future, middle;
double minDistance;
int minPos;
double distance;
for(int i = 0; i < n; i++)
cin >> p[i].x >> p[i].y >> p[i].z;
cin >> acm.x >> acm.y >> acm.z;
cin >> future.x >> future.y >> future.z;
middle.x = (acm.x + future.x) / 2;
middle.y = (acm.y + future.y) / 2;
middle.z = (acm.z + future.z) / 2;
minDistance = DBL_MAX; //#include<cfloat>有宏定义double最大值
for(int i = 0; i < n; i++)
{
distance = sqrt((middle.x - p[i].x)*(middle.x - p[i].x)
+(middle.y - p[i].y)*(middle.y - p[i].y)+
(middle.z - p[i].z)*(middle.z - p[i].z));
if(distance < minDistance)
{
minDistance = distance;
minPos = i;
}
...
登录后发布评论
暂无评论,来抢沙发