题目来源:http://poj.org/problem?id=1046

题目大意:

  在RGB颜色空间中,用下面的公式来度量两个颜色值的距离。

  现给出16个RGB表示的颜色,和一些用于测试的颜色,求被测试的颜色与16个颜色中哪个最相近,有多个距离相等时取输入排在最前的一个颜色。

输入:前16行为给定的颜色,后面的每一行为一个测试用例,每个颜色都是由代表R、G、B的三个整数组成,值在0到255之间。以-1 -1 -1作为输入结束的标志。

输出:对于每个测试的颜色,输出他们的对应关系。格式见sample.


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)

水题,暴力解决。

 //////////////////////////////////////////////////////////////////////////
// POJ1046 Color Me Less
// Memory: 268K Time: 0MS
// Language: C++ Result: Accepted
////////////////////////////////////////////////////////////////////////// #include <iostream>
#include <cmath> using namespace std; struct Color {
int r, g, b;
}; Color color[]; double distance(int i, int &r, int &g, int &b) {
return sqrt((float)(color[i].r - r) * (color[i].r - r)
+ (color[i].g - g) * (color[i].g - g)
+ (color[i].b - b) * (color[i].b - b));
} int main(void) {
for (int i = ; i < ; ++i) cin >> color[i].r >> color[i].g >> color[i].b;
int id = ;
while (true) {
int r, g, b;
cin >> r >> g >> b;
if (r == -) break;
double min_d = distance(, r, g, b);
int min_id = ;
for (int i = ; i < ; ++i) {
double d = distance(i, r, g, b);
if (d < min_d) {
min_id = i;
min_d = d;
}
}
cout << "(" << r << "," << g << "," << b << ")" << " maps to "
<< "(" << color[min_id].r << "," << color[min_id].g << ","
<< color[min_id].b << ")" << endl;
}
system("pause");
return ;
}

POJ1046 Color Me Less的更多相关文章

  1. 【转】c#、wpf 字符串,color,brush之间的转换

    转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...

  2. Python为8bit深度图像应用color map

    图片中存在着色版的概念,二维矩阵的每个元素的值指定了一种颜色,因此可以显示出彩色. 迁移调色板 下述python代码将VOC数据集中的某个语义分割的图片的调色板直接应用在一个二维矩阵代表的图像上 #l ...

  3. (转)System.Drawing.Color的颜色对照表

    经常使用System.Drawing.Color, 本篇介绍一下颜色与名称及RGB值的对应关系. 1. 颜色与名称的对照表(点击下图放大看): 2. 颜色与RGB值对照表: Color.AliceBl ...

  4. 激光打印机的Color/paper, Xerography介绍

    Color Basic 看见色彩三要素: 光源,物体,视觉 加色色彩模型:R,G,B 多用于显示器 减色色彩模型:C,M,Y,K 多用于打印复印 Paper 东亚地区常用A系列标准用纸,在多功能一体机 ...

  5. 安卓工具箱:color of Style

    <?xml version="1.0" encoding="utf-8"?> <resources> <color name=&q ...

  6. UITableView 一直显示滚动条(ScrollBar Indicators)、滚动条Width(宽度)、滚动条Color(颜色)

    在 IOS 中,对 UIScrollView 的滚动条(ScrollBar Indicators)的自定义设置接口,一直都是很少的.除了能自定义简单的样式(UIScrollViewIndicatorS ...

  7. OpenCASCADE Color Scale

    OpenCASCADE Color Scale eryar@163.com Abstract. The color scale is a specialized label object that d ...

  8. Color Transfer between Images code实现

    上计算机视觉课老师布置的作业实现论文:Color Transfer between Images 基本思路是: 1.给定srcImg和targetImg 2.将RGB空间转为Lab空间 3.根据论文中 ...

  9. ZOJ Problem Set - 1067 Color Me Less

    这道题目很简单,考察的就是结构体数组的应用,直接贴代码了 #include <stdio.h> #include <math.h> typedef struct color { ...

随机推荐

  1. FEC之我见四

    接上文,来详细的说明一下FEC前向纠错的具体实现: FEC_matrix是一个比较常用的算法,Vandermonde,范德蒙矩阵是法国数学家范德蒙提出的一种各列为几何级数的矩阵. 范德蒙矩阵的定义: ...

  2. ACM学习历程—UVALive 7147 World Cup(分类讨论 && 贪心)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  3. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

  4. CSS之EM相对单位

    之前以为em单位只是在font-size中起到继承作用, 后来慢慢觉得,继承,应该是在几乎所有样式中都可以是实现的,比如height,width,border... 今天才简单测试了下,果真是可以实现 ...

  5. 使用Visual Studio进行单元测试-Part2

    写在开头:Coding ain't done until all the tests run. No unit test no BB. 另外有童鞋在上一篇博文留言说找不到Add Fake Assemb ...

  6. Poj 1742 Coins(多重背包)

    一.Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dolla ...

  7. C++输入输出知识

    1.strtok将字符串中的单词用' '分割出来 #include<iostream> #include<cstdio> #include<cstdlib> #in ...

  8. 机器学习:Jupyter Notebook中Matplotlib的使用

    一.matplotlib绘制折线图 matplotlib绘图的实质是折线图,将所有的点用直线连接起来,由于距离比较密,看起来像是个平滑的曲线: import matplotlib as mpl:加载m ...

  9. VMware Workstation虚拟机安装Windows 7系统

    1.进入VMware Workstation虚拟机软件界面,选择新建虚拟机

  10. Windchill 预览效果偏向左边

    文档预览效果偏左 解决方法: 1.修改worker配置,去掉“fit worksheet to a single page”的勾 2.进行services,重新启动以下服务 3.重启windchill ...