POJ 1046 Color Me Less解题报告
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 1046 Color Me Less解题报告相关的知识,希望对你有一定的参考价值。
Description
A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just such a mapping in a standard twenty-four bit RGB color space. The input consists of a target set of sixteen RGB color values, and a collection of arbitrary RGB colors to be mapped to their closest color in the target set. For our purposes, an RGB color is defined as an ordered triple (R,G,B) where each value of the triple is an integer from 0 to 255. The distance between two colors is defined as the Euclidean distance between two three-dimensional points. That is, given two colors (R1,G1,B1) and (R2,G2,B2), their distance D is given by the equation
Input
The input is a list of RGB colors, one color per line, specified as three integers from 0 to 255 delimited by a single space. The first sixteen colors form the target set of colors to which the remaining colors will be mapped. The input is terminated by a line containing three -1 values.
Output
For each color to be mapped, output the color and its nearest color from the target set.
If there are more than one color with the same smallest distance, please output the color given first in the color set.
If there are more than one color with the same smallest distance, please output the color given first in the color set.
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 }
以上是关于POJ 1046 Color Me Less解题报告的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode --- 1046. Last Stone Weight 解题报告
LeetCode --- 1046. Last Stone Weight 解题报告
zabbix导入数据库报错1046 (3D000) : No database selected
zabbix导入数据库报错1046 (3D000) : No database selected
POJ训练计划2777_Count Color(线段树/成段更新/区间染色)
Zabbix导入MySQL数据库报错ERROR 1046 (3D000) at line 1: No database selected