• 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 }
  • 相关阅读:
    刷新页面的问题
    JS属性
    1-4_基本概念_进程间通信及同步
    1-3_基本概念_程序&进程
    1-2_基本概念_用户和组&目录、链接及文件
    1-1_基本概念_内核&shell
    d 操作系统概述
    对比生成测试算法用例
    简单的排序算法:冒泡排序法
    简单的排序算法:插入排序法
  • 原文地址:https://www.cnblogs.com/cszlg/p/3246745.html
Copyright © 2020-2023  润新知