码迷,mamicode.com
首页 > 其他好文 > 详细

POJ-1046

时间:2015-07-12 01:50:04      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ-1046

标签:

原文地址:http://blog.csdn.net/eddy_liu/article/details/46846377

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!