题目来源: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. PS 滤镜— —Marble 效果

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  2. Mybatis学习--Sql语句构建器

    学习笔记,选自Mybatis官方中文文档:http://www.mybatis.org/mybatis-3/zh/statement-builders.html 问题 Java程序员面对的最痛苦的事情 ...

  3. LeetCode:Add Digits - 非负整数各位相加

    1.题目名称 Add Digits (非负整数各位相加) 2.题目地址 https://leetcode.com/problems/add-digits/ 3.题目内容 英文:Given a non- ...

  4. Marionettejs

    Marionette是牵线木偶的意思,这个库是对Backbone的一次更高层次封装.这样的封装有两个目标: 减少重复的工作,提高使用Backbonejs时的生产效率给复杂应用页面提供更多的结构,以支撑 ...

  5. POJ2513(字典树+图的连通性判断)

    //用map映射TLE,字典树就AC了#include"cstdio" #include"set" using namespace std; ; ;//26个小 ...

  6. oracle上课 学习2 oracle 游标 存储过程 有用

    1.1. 训练描述 使用游标,打印emp中20号部门的所有员工的信息 操作步骤答案 declare cursor c_emp  is select * from emp where deptno=10 ...

  7. 将Linux 标准输出,错误输出重定向到文件

    1.想要把make输出的全部信息,输出到某个文件中,最常见的办法就是: make xxx > build_output.txt 此时默认情况是没有改变2=stderr的输出方式,还是屏幕,所以, ...

  8. 1、linux-wget

    1.常用下载与参数 wget + 空格 + 要下载文件的url路径 例如: # wget linuxsense.org/xxxx/xxx.tar.gz">http://www.linu ...

  9. isPCR安装

    isPCR是用一对PCR引物搜索序列数据库.它使用索引策略来快速完成此操作.当搜索成功时,输出是fasta格式序列文件,其包含数据库中位于引物对之间的所有区域. Linux系统下安装 1. 使用二进制 ...

  10. JavaEE资源

    JavaEE资源   http://bbs.itheima.com/forum.php?mod=forumdisplay&fid=183