poj1046

简单题

View Code
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

using namespace std;



#define maxn 20



struct Point

{

    int x, y, z;

} point[maxn], s;



int dist(Point a, Point b)

{

    Point v;

    v.x = a.x - b.x;

    v.y = a.y - b.y;

    v.z = a.z - b.z;

    return v.x * v.x + v.y * v.y + v.z * v.z;

}



int main()

{

    //freopen("t.txt", "r", stdin);

    for (int i = 0; i < 16; i++)

        scanf("%d%d%d", &point[i].x, &point[i].y, &point[i].z);

    while (~scanf("%d%d%d", &s.x, &s.y, &s.z))

    {

        if (s.x == -1 && s.y == -1 && s.z == -1)

            break;

        int temp = 0;

        for (int i = 1; i < 16; i++)

            if (dist(s, point[i]) < dist(s, point[temp]))

                temp = i;

        printf("(%d,%d,%d) maps to (%d,%d,%d)\n", s.x, s.y, s.z, point[temp].x, point[temp].y, point[temp].z);

    }

    return 0;

}

 

你可能感兴趣的:(poj)