关闭

zoj 1067 Color Me Less

标签: zoj
275人阅读 评论(0) 收藏 举报
分类:
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

The input file 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.


Example

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

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)


分析:

实际上就是求最近的两点(可以是同一点),因为颜色集合只有16个元素,所以直接枚举所有情况比较大小可得结果。

算D时不用开方。

代码:

#include <cstdio>

const int MAX_N = 16;

typedef struct {
    int r;
    int g;
    int b;
} color;

color colSet[MAX_N];
int dis[MAX_N];

void getDis(color c) {
    for (int i = 0; i < MAX_N; i++)
        dis[i] = (c.r - colSet[i].r) * (c.r - colSet[i].r) + (c.g - colSet[i].g) * (c.g - colSet[i].g) + (c.b - colSet[i].b) * (c.b - colSet[i].b);
}

void solve() {
    color c;
    while (~scanf("%d%d%d", &c.r, &c.g, &c.b) && c.r != -1) {
        getDis(c);
        int mini = 0;
        for (int i = 1; i < MAX_N; i++)
            if (dis[i] < dis[mini])
                mini = i;
        printf("(%d,%d,%d) maps to (%d,%d,%d)\n", c.r, c.g, c.b, colSet[mini].r, colSet[mini].g, colSet[mini].b);
    }
}

int main() {
    for (int i = 0; i < MAX_N; i++)
        scanf("%d%d%d", &colSet[i].r, &colSet[i].g, &colSet[i].b);
    solve();
    return 0;
}


0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

LESS详解之混合(Mixins)高级

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

mysql免安装配置教程及遇到1067服务启动不成功的问题解决方法

mysql免安装配置简洁教程及遇到问题的解决方法
  • Yonk_Z
  • Yonk_Z
  • 2016-05-31 17:50
  • 3054

Css编译之Less入门

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

zoj 1067 Color Me Less

正确代码: #include #include #include using namespace std; int main() { int tar[16][3]; for(int i=0;...
  • u010772673
  • u010772673
  • 2014-12-25 11:35
  • 391

ZOJ 1067Color Me Less

Time Limit: 1 Second      Memory Limit: 32768 KB ProblemA color reduction is a mapping from a set of...
  • cqlf__
  • cqlf__
  • 2011-05-27 23:34
  • 743

ZOJ--1067:Color Me Less

思路: 这题是让 先输入十六组数 然后给后面的每组数 从这十六组数中找通过那个式子值最小的 一组数据 ; 比较简单 不解释 java: import java.util.Scanner; p...
  • yf224
  • yf224
  • 2017-06-14 22:11
  • 115

ZOJ 1067 Color Me Less

Color Me Less Time Limit: 2 Seconds      Memory Limit: 65536 KB Problem A color reduction i...
  • wpfengqi
  • wpfengqi
  • 2012-08-23 14:12
  • 220

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
  • 537

<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
    个人资料
    • 访问:8880次
    • 积分:509
    • 等级:
    • 排名:千里之外
    • 原创:44篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类