poj 1046(Color Me Less)

原创 2011年09月12日 22:36:28
 
Color Me Less
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23677   Accepted: 11270

Description

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

Input

The input is a list of RGB colors, one color per line, specified as three integers from 0 to 255 delimited by a single space. The first sixteen colors form the target set of colors to which the remaining colors will be mapped. The input is terminated by a line containing three -1 values.

Output

For each color to be mapped, output the color and its nearest color from the target set.

If there are more than one color with the same smallest distance, please output the color given first in the color set.

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)

Source

 
#include<map>
#include<cstdio>
#include<iostream>
#include<map>
#include<cmath>

#define MAXN 110
#define MAXLEN 55

using namespace std;

struct RGB{
    int R,G,B;
}maap[219];

void input(){
    int a, b, c;
    int count = 0;
    while(scanf("%d%d%d", &a,&b,&c)){
        maap[count].R = a;
        maap[count].G = b;
        maap[count].B = c;
        count++;
        if(count == 16)  break;
    }
}

double dis(RGB a, RGB b){
    return sqrt((a.R - b.R) * (a.R - b.R) + (a.G - b.G) * (a.G - b.G) +
                      (a.B - b.B) * (a.B - b.B));
}
RGB cal_dis(RGB rgb[], RGB a){
    int flag = 0;
    double min = dis(rgb[0], a);
    for(int i = 1; i < 16; i++){
        if(dis(rgb[i], a) < min){
            min = dis(rgb[i], a);
            flag = i;
        }
    }
    return rgb[flag];
}
int main(){
    input();
    int a,b,c;
    while(scanf("%d%d%d", &a,&b, &c) && a != -1 || b != -1 || c != -1){
        RGB rr;
        rr.R = a;rr.G = b;rr.B = c;
        printf("(%d,%d,%d) maps to (%d,%d,%d)\n", a, b, c,
               cal_dis(maap,rr).R, cal_dis(maap,rr).G, cal_dis(maap,rr).B);
    }
    return 0;
}

LESS详解之混合(Mixins)高级

现在已经为大家介绍了LESS之混合(Mixins)的一些用法了,相信大家也用了不少有关LESS之混合(Mixins)了。接下来将为大家介绍一些有关LESS之混合(Mixins)的另外一些使用方法,可算...
  • LiMengXiaoLong
  • LiMengXiaoLong
  • 2013年11月06日 09:02
  • 6124

Css编译之Less入门

为什么要有预处理CSS? css写起来比较费事,而且代码难以维护 , 后来,就有了让CSS加入一些编程的元素,像其他程序语言一样可以做一些预定的处理,这就是 CSS预处理器( CSS Prepr...
  • Tyro_java
  • Tyro_java
  • 2016年05月13日 10:25
  • 3398

NodeJS的安装以及Less编译器的安装调用

1、首先从官网https://nodejs.org/en/下载nodejs稳定版 ; 2、按步骤安装好; 3、打开电脑的cmd.exe; 4、输入node  -v 回车查看版本,然后输入npm  --...
  • St_Sp_En
  • St_Sp_En
  • 2017年02月22日 21:17
  • 1750

POJ 1046-Color Me Less【暴力】

A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this ...
  • qq_29600137
  • qq_29600137
  • 2016年03月03日 14:31
  • 212

POJ1046,Color Me Less,心情不爽就去切水

Color Me Less Description A color reduction is a mapping from a set of discrete colors to a sm...
  • Stand_over_sun
  • Stand_over_sun
  • 2012年11月19日 21:24
  • 407

POJ1046 Color Me Less(水题就当玩吧)

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31681   ...
  • u013021513
  • u013021513
  • 2015年05月30日 22:14
  • 536

<poj 1046>Color Me Less

Color Me Less   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25873 ...
  • cs_zlg
  • cs_zlg
  • 2012年07月14日 12:02
  • 553

1046 poj Color Me Less

题意:匹配距离最小的两组数,先给你16个数据,然后再输入数据直到输入三个-1结束输入            把后输入的数据与前16个数据进行匹配,如果他们之间的距离在所有数据匹配中最小      ...
  • Tdreamge
  • Tdreamge
  • 2012年04月09日 18:30
  • 460

POJ1046——Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33605   ...
  • LDUtyk
  • LDUtyk
  • 2016年11月15日 15:46
  • 198

POJ 1046 Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31449   Accepted: 1...
  • u013068502
  • u013068502
  • 2015年04月10日 20:55
  • 386
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 1046(Color Me Less)
举报原因:
原因补充:

(最多只允许输入30个字)