Color Me Less

Color Me Less


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Problem

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

Color Me Less

 #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; int main()
{
int r[], b[], g[];
for(int i = ; i < ; i++)
{
scanf("%d %d %d", r + i, g + i, b + i);
}
int x, y, z;
while(scanf("%d %d %d", &x, &y, &z))
{
if(x == - && y == - && z == -) break;
double minD = (x - r[]) * (x - r[]) + (y - g[])* (y - g[]) + (z - b[]) * (z - b[]);
int id = ;
for(int i = ; i < ; i++)
{
double D = (x - r[i]) * (x - r[i]) + (y - g[i]) * (y - g[i]) + (z - b[i]) * (z - b[i]);
if(minD > D)
{
minD = D;
id = i;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n", x, y, z, r[id], g[id], b[id]);
// cout << id << endl;
}
return ;
}
上一篇:大熊君JavaScript插件化开发------(第二季)


下一篇:TinyFrame升级之八:实现简易插件化开发