POJ-1046

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

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

时间: 2024-10-13 22:24:03

POJ-1046的相关文章

POJ 1046 Color Me Less 最详细的解题报告

题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ Math.pow((left.green - right.green), 2)+ Math.pow((left.blue - right.blue), 2)) 表示两个不同颜色的之间的距离(以left和right为例,left和right分别为两种不同的颜色),现给出16组目标颜色,剩下的为待匹配的颜

[ACM] POJ 1046 Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30146   Accepted: 14634 Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just

poj 1046 Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33007   Accepted: 16050 Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just

POJ 1046 Color Me Less解题报告

Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just such a mapping in a standard twenty-four bit RGB color space. The input consists of a target set of

HDU 1046 &amp; POJ 1450 Gridland【有趣的数学题】

Gridland Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5697    Accepted Submission(s): 2607 Problem Description For years, computer scientists have been trying to find efficient solutions to

【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑

倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到E,恰好经过N条边的最短路径(姑且称为路径吧,虽然好像已经不是了……) 总共只有大约200个点(很多点根本没走到,离散化一下即可)所以可以考虑Floyd算最短路. 引用下题解: 题目求i,j之间边数恰为N的最短路径(边可以重复走),我们知道线性代数中有:01邻接矩阵A的K次方C=A^K,C[i][j

POJ 1300.Door Man 欧拉通路

Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2596   Accepted: 1046 Description You are a butler in a large mansion. This mansion has so many rooms that they are merely referred to by number (room 0, 1, 2, 3, etc...). Your mas

POJ题目推荐(转载)

POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求,当然有能力的同学可以直接切掉.2.标记为A and B的题目是比较相似的题目,建议大家两个一起做,可以对比总结,且二者算作一个题目.3.列表中大约有70个题目.大家选做其中的50道,且每类题目有最低数量限制.4.这里不少题目在BUPT ACM FTP上面都有代码,请大家合理利用资源.5.50个题目要求每个题目都要写总结,养成良好的习惯.6.这个列表的目的在于让大家对各个方面的算法有个了解,也许要求有些苛刻,教条,请大家谅

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京