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 }
  • 相关阅读:
    js----定义变量的几种方式
    Vue----项目增加百度统计
    Vuex----核心概念和API
    Vuex----理解
    回到学校,国庆收假的第一天
    再次回到武汉
    收获的季节,最忙其实也是最没有收获的时光
    虚无缥缈的自信,一落千丈的打击
    愤怒、愤怒,终于适应了奔波
    总是骗人的你
  • 原文地址:https://www.cnblogs.com/cszlg/p/3246745.html
Copyright © 2011-2022 走看看