题意:匹配距离最小的两组数,先给你16个数据,然后再输入数据直到输入三个-1结束输入
把后输入的数据与前16个数据进行匹配,如果他们之间的距离在所有数据匹配中最小
就输出
/*
Sample Input
0 0 0
255 255 255
0 0 1
1 1 1
128 0 0
0 128 0
128 128 0
0 0 128
126 168 9
35 86 34
133 41 193
128 0 128
0 128 128
128 128 128
255 0 0
0 1 0
0 0 0
255 255 255
253 254 255
77 79 134
81 218 0
-1 -1 -1
Sample Output
(0,0,0) maps to (0,0,0)
(255,255,255) maps to (255,255,255)
(253,254,255) maps to (255,255,255)
(77,79,134) maps to (128,128,128)
(81,218,0) maps to (126,168,9)
*/
#include<stdio.h>
#define INF 0xfffffff
struct Node
{
int x,y,z;
}target[1000],mapp[1000],Rem[1000];
int distance(Node a,Node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}
int main()
{
int i,j;
for (i=1;i<=16;i++)
scanf("%d%d%d",&target[i].x,&target[i].y,&target[i].z);
int cas=1;
while(1)
{
scanf("%d%d%d",&mapp[cas].x,&mapp[cas].y,&mapp[cas].z);
if(mapp[cas].x==-1 && mapp[cas].y==-1 && mapp[cas].z==-1) break;
cas++;
}
int dis,k;
for (i=1;i<cas;i++)
{
dis=INF;
for (j=1;j<=16;j++)
{
if(target[j].x==-1) continue;
if(dis>distance(mapp[i],target[j]))
{
dis=distance(mapp[i],target[j]);
k=j;
}
}
Rem[i]=target[k];
target[j].x=-1;//If there are more than one color with the same smallest distance
}
for (i=1;i<cas;i++)
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",mapp[i].x,mapp[i].y,mapp[i].z,
Rem[i].x,Rem[i].y,Rem[i].z);
//system("pause");
return 0;
}