标签:
#include<iostream> #include<cmath> #include<list> using namespace std; typedef struct coordinate{ int x; int y; int z; }SCoordinate; typedef struct input{ SCoordinate cTarget; SCoordinate cInput; }SInput; int main(int argc, char *argv[]){ list<SCoordinate> mListTarget; list<SInput> mListInput; SCoordinate mCoordinate; SInput mInput; int distence; for(int i=0;i<16;i++){ cin>>mCoordinate.x>>mCoordinate.y>>mCoordinate.z; mListTarget.push_back(mCoordinate); } while(1){ cin>>mInput.cInput.x>>mInput.cInput.y>>mInput.cInput.z; if(mInput.cInput.x==-1 && mInput.cInput.y==-1 && mInput.cInput.z==-1){ break; } distence=255*255*3+1; for(list<SCoordinate>::iterator iter=mListTarget.begin(); iter!=mListTarget.end();++iter){ int tmpDistence=sqrt(pow(1.0*mInput.cInput.x-iter->x,2) +pow(1.0*mInput.cInput.y-iter->y,2) +pow(1.0*mInput.cInput.z-iter->z,2)); if(distence>tmpDistence){ mInput.cTarget.x=iter->x; mInput.cTarget.y=iter->y; mInput.cTarget.z=iter->z; distence=tmpDistence; } } mListInput.push_back(mInput); } for(list<SInput>::iterator iter=mListInput.begin(); iter!=mListInput.end(); ++iter){ cout<<"("<<iter->cInput.x<<","<<iter->cInput.y<<","<<iter->cInput.z <<") maps to ("<<iter->cTarget.x<<","<<iter->cTarget.y<<","<<iter->cTarget.z<<")"<<endl; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/eddy_liu/article/details/46846377