博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1406
阅读量:4841 次
发布时间:2019-06-11

本文共 1881 字,大约阅读时间需要 6 分钟。

1.链接地址

2.问题描述

 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 

输入样例

0 0 0255 255 2550 0 11 1 1128 0 00 128 0128 128 00 0 128126 168 935 86 34133 41 193128 0 1280 128 128128 128 128255 0 00 1 00 0 0255 255 255253 254 25577 79 13481 218 0-1 -1 -1

输出样例

(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)

3.解题思路

枚举比较即可

4.算法实现源代码

#include
#include
using namespace std; struct RGB{ double r; double g; double b;}; int main(){ RGB a[16]; for(int i=0;i<16;i++) { cin>>a[i].r>>a[i].g>>a[i].b; } RGB b[100]; RGB c[100]; double e1,g1,b1,num,l; int cnt=0; while(cin>>e1>>g1>>b1&&(e1!=-1&&g1!=-1&&b1!=-1)) { num=1000; b[cnt].r=e1; b[cnt].g=g1; b[cnt].b=b1; for(int i=0;i<16;i++) { l=sqrt(pow((a[i].r-e1),2)+pow((a[i].g-g1),2)+pow((a[i].b-b1),2)); if(num>l) { num=l; c[cnt].r=a[i].r; c[cnt].g=a[i].g; c[cnt].b=a[i].b; } } cnt++; } for(int i=0;i

 

转载于:https://www.cnblogs.com/KasenBob/p/11180483.html

你可能感兴趣的文章
动态规划:HDU1712-ACboy needs your help(分组背包问题)
查看>>
PAT A1009 Product of Polynomials(25)
查看>>
libFFM 与 python-libffm 安装遇到的一系列问题-解决方案
查看>>
数据摘要pandas
查看>>
浅谈C语言中的位段
查看>>
2019.04.25 第七次训练 【2017-2018 ACM-ICPC Asia East Continent League Final (ECL-Final 2017)】...
查看>>
javascript正则表达式复习
查看>>
【JVM】类加载器及双亲委派机制实例解析
查看>>
python 生成 pyc 文件
查看>>
linux清除git账号密码
查看>>
grep awk 查看nginx日志中所有访问的ip并 去重
查看>>
vue 遇到防盗链 img显示不出来
查看>>
C# GDI graphics.DrawImage 的参数问题
查看>>
【WPF】2、美化控件
查看>>
css 光标
查看>>
深入理解await与async
查看>>
将一个数字扁平化,去重并升序
查看>>
边缘缓存模式(Cache-Aside Pattern)
查看>>
博文汇总
查看>>
在Java大环境下.NET程序员如何夺得一线生机
查看>>