水题,不用解释
#include "iostream" #include "vector" using namespace std; int Gis(int * Ppt,short (*Goal)[3],size_t i) { int Gisd = (Ppt[0] - Goal[i][0]) * (Ppt[0] - Goal[i][0]); Gisd += (Ppt[1] - Goal[i][1]) * (Ppt[1] - Goal[i][1]); Gisd += (Ppt[2] - Goal[i][2]) * (Ppt[2] - Goal[i][2]); return Gisd; } void GetDis(int * Ppt,short (*Goal)[3]) { int Min = Gis(Ppt,Goal,0); Ppt[3] = 0; for( size_t ix = 1 ; ix != 16 ; ix ++ ) { if(Min > Gis(Ppt,Goal,ix)) { Ppt[3] = ix; Min = Gis(Ppt,Goal,ix); } } } int main(void) { short Goal[16][3]; for( size_t ix = 0 ; ix != 16 ; ix ++ ) cin >> Goal[ix][0] >> Goal[ix][1] >> Goal[ix][2]; vector<int *> Ppt; for( size_t id = 0 ; true ; id ++ ) { Ppt.push_back(new int[4]); cin >> Ppt[id][0] >> Ppt[id][1] >> Ppt[id][2]; if( ( Ppt[id][0] == -1 && Ppt[id][1] == -1 ) && Ppt[id][2] == -1 )break; else GetDis(Ppt[id],Goal); } for( size_t i = 0 ; i != Ppt.size() - 1; i ++ ) { cout << "(" << Ppt[i][0] << "," << Ppt[i][1]; cout << "," << Ppt[i][2] << ")" << " maps to "; cout << "(" << Goal[Ppt[i][3]][0] << "," << Goal[Ppt[i][3]][1]; cout << "," << Goal[Ppt[i][3]][2] << ")" << endl; } return 0; }