题目来源: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. bzoj 3994 约数个数和 —— 反演+数论分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3994 推导过程和这里一样:https://www.cnblogs.com/MashiroSk ...

  2. mysql 用户和存储过程相关命令

    如何显示所有的存储过程?select `name` from mysql.proc where db='db_name' and `type`='procedure';orshow procedure ...

  3. JAVA 1.5 并发之 Executor框架 (内容为转载)

    本文内容转自 http://www.iteye.com/topic/366591 Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Exec ...

  4. kubeadm 搭建 K8S集群

    kubeadm是K8s官方推荐的快速搭建K8s集群的方法. 环境: Ubuntu 16.04 1 安装docker Install Docker from Ubuntu’s repositories: ...

  5. VMware VirtualCenter Server service fails to start with the vpxd.log error: ODBC error: (28000) (1017688)

    Symptoms If you experience an ungraceful shutdown of the database (for example, because of a power o ...

  6. web安全之同源策略

    为什么使用同源策略?一个重要原因就是对cookie的保护,cookie 中存着sessionID .如果已经登录网站,同时又去了任意其他网站,该网站有恶意JS代码.如果没有同源策略,那么这个网站就能通 ...

  7. 洛谷-机器翻译-NOIP2010提高组复赛

    题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词,软件会先 ...

  8. 第2天视频 08_androidHelloworld

    为什么应用的包名要用公司域名倒写呢?如何区分不同的安卓应用?高版本的应用装了之后会把低版本的应用覆盖掉.如果是不同的应用跟其他应用没关系只要装上去就可以了.区别不同的应用用的比较关键的东西是一个是应用 ...

  9. 20、BLAST比对及结果介绍

    1.formatdb -i /share/nas1/huangt/project/IsoSeq/BMK170104-E545-03-a/Analysis_T01/MoveRebundant/T01/c ...

  10. Python通过调用windows命令行处理sam文件

    Python通过调用windows命令行处理sam文件 以samtools软件为例 一.下载或者索取得到windows版本的samtools软件,解压后如下: 进入文件内部,有如下几个文件: 二.将s ...