Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简短AC代码,有解释//实质就是让你求离在空间直角坐标系中某个给定的点的距离最近的那个点的坐标,即所谓的map(映射) //注意:If there are more than one color with the same smallest distance, //please output the color given first in the color set. #include<iostream> using namespace std; int f(int a, int b, int c) { return a*a + b*b + c*c; } struct color { int R; int G; int B; }c[16]; int main() { int x, y, z, i, m, n, l,min; //min记录所求的点的索引值(数组元素下标) for (i = 0; i < 16; i++) { cin >> x >> y >> z; c[i].R = x; c[i].G = y; c[i].B = z; } while (cin >> m >> n >> l&&!((m == -1) && (n == -1) && (l == -1))) { min = 0; for (i = 1; i < 16; i++) { if (f(m - c[i].R, n - c[i].G, l - c[i].B) < f(m - c[min].R, n - c[min].G, l - c[min].B)) min = i; } cout << "(" << m << "," << n << "," << l << ") maps to (" << c[min].R << "," << c[min].G << "," << c[min].B << ")\n"; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator