进网站后台加什么原因,html网站源码,重庆微信网站开,河南郑州做网站的公司问题 颜色缩减是从一组离散颜色到较小颜色的映射。这个问题的解决方案需要在标准的24位RGB颜色空间中执行这样的映射。输入由十六个RGB颜色值的目标集合和要映射到目标集合中最接近的颜色的任意RGB颜色集合组成。为了我们的目的#xff0c;RGB颜色被定义为有序三元组#xff…问题 颜色缩减是从一组离散颜色到较小颜色的映射。这个问题的解决方案需要在标准的24位RGB颜色空间中执行这样的映射。输入由十六个RGB颜色值的目标集合和要映射到目标集合中最接近的颜色的任意RGB颜色集合组成。为了我们的目的RGB颜色被定义为有序三元组RGB其中三元组的每个值都是从0到255的整数。两种颜色之间的距离被定义为两个三维点之间的欧几里得距离。也就是说给定两种颜色R1G1B1和R2G2B2它们的距离D由下式给出 输入 文件是RGB颜色的列表每行一种颜色指定为由单个空格分隔的从0到255的三个整数。前十六种颜色形成了剩余颜色将映射到的目标颜色集。输入由包含三个-1值的行终止。 输出 对于要映射的每个颜色输出颜色及其与目标集最近的颜色。
Example
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
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)
思路
相当于通过求三维坐标中两点距离找出距离最近的两点。
AC代码
#include iostream
#include cstdio
#include cmath
#include vector
#include climits
#define AUTHOR HEX9CF
using namespace std;int main()
{vectorvectorint data;vectorvectorint ask;int x, y, z;for (int i 0; i 16; i){cin x y z;data.push_back({x, y, z});}while (cin x y z){if (-1 x x y y z){break;}ask.push_back({x, y, z});}vectorvectorint::iterator ita ask.begin();for (; ita ! ask.end(); ita){float mind 999.;int map[6];vectorvectorint::iterator itd data.begin();for (; itd ! data.end(); itd){float d sqrt(pow(((*itd)[0] - (*ita)[0]), 2) pow(((*itd)[1] - (*ita)[1]), 2) pow(((*itd)[2] - (*ita)[2]), 2));if (d mind){mind d;map[0] (*ita)[0];map[1] (*ita)[1];map[2] (*ita)[2];map[3] (*itd)[0];map[4] (*itd)[1];map[5] (*itd)[2];}// cout d endl;}// cout mind endl;printf((%d,%d,%d) maps to (%d,%d,%d)\n, map[0], map[1], map[2], map[3], map[4], map[5]);}return 0;
}