Description
给出16行数字,再输入数据,找到前面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)
题解:
整理ing
AC_Code(cpp):
#include<iostream>
using namespace std;
int temp[3];
int vis[16][3] = { 0 };
int solve(int a[])
{
int s = (a[0] - temp[0])*(a[0] - temp[0]);
s += (a[1] - temp[1])*(a[1] - temp[1]);
s += (a[2] - temp[2])*(a[2] - temp[2]);
return s;
}
int main()
{
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> vis[i][j];
}
}
while (1)
{
for (int i = 0; i < 3; i++)
{
cin >> temp[i];
}
if (temp[0] == -1)
break;
int t = 0;
int ans = solve(vis[0]);
for (int i = 1; i < 16; i++)
{
if (ans>solve(vis[i]))
{
t = i;
ans = solve(vis[i]);
}
}
cout << "(" << temp[0] << "," << temp[1] << "," << temp[2] << ") maps to (" << vis[t][0] << "," << vis[t][1] << "," << vis[t][2] << ")" << endl;
}
return 0;
}