标签:
Description
Input
Output
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)
大水题,本来没必要记的。可还是出了问题,说明自己更水!!
首先,自己理解题意太慢了,刷题太少,思维不够专注。其次,语言不熟,基础不扎实,把异或当平方用,肯定是MATLAB用的中毒太深。结果不报错,调试通过-1.#IND00才发现的。基础不扎实真的会浪费更多时间啊!
AC代码
1 #include <cstdio> 2 #include <cmath> 3 typedef struct Color 4 { 5 int R; 6 int G; 7 int B; 8 }RGB; 9 int main(int argc, char const *argv[]) 10 { 11 RGB T[16]; 12 for (int i = 0; i < 16; i++){ 13 scanf("%d%d%d", &T[i].R, &T[i].G, &T[i].B); 14 } 15 int r, g, b; 16 17 while (1){ 18 scanf("%d%d%d", &r, &g, &b); 19 if (-1 == r || -1 == g || -1 == b) 20 break; 21 int mark = 0; 22 double D = 1e7 + 1.0; 23 double temp = 0; 24 for (int i = 0; i < 16; i++){ 25 temp = sqrt((double)((T[i].R - r)*(T[i].R - r) + (T[i].G - g)*(T[i].G - g) + (T[i].B - b)*(T[i].B - b))); 26 if (temp < D){ 27 D = temp; 28 mark = i; 29 } 30 } 31 printf("(%d,%d,%d) maps to (%d,%d,%d)\n", r, g, b, T[mark].R, T[mark].G, T[mark].B); 32 } 33 return 0; 34 }
标签:
原文地址:http://www.cnblogs.com/zhaoyu1995/p/5354883.html