zoukankan      html  css  js  c++  java
  • Color Me Less

    Color Me Less

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Problem

    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

     

     1 #include <iostream>
     2 #include <string>
     3 #include <algorithm>
     4 #include <map>
     5 #include <vector>
     6 #include <cstdio>
     7 #include <cmath>
     8 #include <cstring>
     9 using namespace std;
    10 
    11 int main()
    12 {
    13     int r[16], b[16], g[16];
    14     for(int i = 0; i < 16; i++)
    15     {
    16         scanf("%d %d %d", r + i, g + i, b + i);
    17     }
    18     int x, y, z;
    19     while(scanf("%d %d %d", &x, &y, &z))
    20     {
    21         if(x == -1 && y == -1 && z == -1) break;
    22         double minD = (x - r[0]) * (x - r[0]) + (y - g[0])* (y - g[0]) + (z - b[0]) * (z - b[0]);
    23         int id = 0;
    24         for(int i = 1; i < 16; i++)
    25         {
    26             double D = (x - r[i]) * (x - r[i]) + (y - g[i]) * (y - g[i]) + (z - b[i]) * (z - b[i]);
    27             if(minD > D)
    28             {
    29                 minD = D;
    30                 id = i;
    31             }
    32         }
    33         printf("(%d,%d,%d) maps to (%d,%d,%d)
    ", x, y, z, r[id], g[id], b[id]);
    34       //  cout << id << endl;
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    冒泡排序
    二分查找
    数3退1的java实现
    列出目录下对应的子目录及文件
    errno相关
    Fibonacci
    windows 下查看Python 的安装路径
    20条编程经验
    [转]一位程序员工作10年总结的13个忠告
    Sql查询语句过滤重复的数据
  • 原文地址:https://www.cnblogs.com/cszlg/p/3246745.html
Copyright © 2011-2022 走看看