pku1046 Color Me Less

有三维坐标中的16个点,然后又有若干点,求每一个点和前16个点中哪个更近。

View Code
 1 program pku1046(input,output);
2 type
3 node = record
4 x,y,z : longint;
5 end;
6 const
7 oo = 10000000;
8 var
9 color : array[1..16] of node;
10 now : node;
11 answer : byte;
12 procedure init;
13 var
14 i : longint;
15 begin
16 for i:=1 to 16 do
17 readln(color[i].x,color[i].y,color[i].z);
18 end; { init }
19 function calc(x1,x2 : node ):double;
20 begin
21 exit(sqrt(sqr(x1.x-x2.x)+sqr(x1.y-x2.y)+sqr(x1.z-x2.z)));
22 end; { calc }
23 procedure main;
24 var
25 i : byte;
26 min : double;
27 begin
28 readln(now.x,now.y,now.z);
29 while (now.x<>-1)or(now.y<>-1)or(now.z<>-1) do
30 begin
31 min:=oo;
32 for i:=1 to 16 do
33 if calc(color[i],now)<min then
34 begin
35 answer:=i;
36 min:=calc(color[i],now);
37 end;
38 write('(',now.x,',',now.y,',',now.z,') ');
39 write('maps to ');
40 writeln('(',color[answer].x,',',color[answer].y,',',color[answer].z,')');
41 readln(now.x,now.y,now.z);
42 end;
43 end; { main }
44 begin
45 init;
46 main;
47 end.



原文地址:https://www.cnblogs.com/neverforget/p/2410103.html