ZOJ1067 Color Me Less

简介: 复制代码#include <iostream> #include <cmath> #include <limits> using namespace std; const int MAXSIZE = 100; int pos[100];//记录对应的最小值所在位置 struct RGB {//颜.
复制代码#include <iostream>
#include <cmath>
#include <limits>
using namespace std;

const int MAXSIZE = 100;
int pos[100];//记录对应的最小值所在位置
struct RGB
{//颜色结构体
    double red;
    double green;
    double blue;
}colors[MAXSIZE];

double distance(RGB* color1,RGB* color2)
{//计算两个颜色的距离
    double r = color1->red-color2->red;
    double g = color1->green-color2->green;
    double b = color1->blue-color2->blue;
    return sqrt(r*r+g*g+b*b);
}

int main(void)
{
    double r,g,b,dist;
    int count=0,i,j,k;
    while (cin>>r>>g>>b&&(r!=-1&&g!=-1&&b!=-1))
    {
        colors[count].red = r;
        colors[count].green = g;
        colors[count].blue = b;
        ++count;
    }
    double min;
    k = 0;
    for (i=16;i<count;++i)
    {
        min = numeric_limits<double>::max();//记录最小值
        for (j=0;j<16;++j)
        {
            dist = distance(&colors[i],&colors[j]);
            if (dist<min)
            {//距离比当前最小值要小
                min = dist;
                pos[k] = j;//记录最小值位置
            }
        }
        k++;
    }
    for (i=16,k=0;i<count;++i,++k)
    {
        cout<<'('<<colors[i].red<<','<<colors[i].green<<','<<colors[i].blue<<')'<<" maps to ";
        cout<<'('<<colors[pos[k]].red<<','<<colors[pos[k]].green<<','<<colors[pos[k]].blue<<')'<<endl;
    }
    return 0;
}

复制代码



本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/10/27/1320767.html,如需转载请自行联系原作者
目录
相关文章
|
2月前
|
Java
hdu-1312-Red and Black
hdu-1312-Red and Black
17 0
|
12月前
HDU - 1312 Red and Black(DFS)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles. Write a program to count the number of black
65 0
hdu 1312 Red and Black
一个人从@点出发,求他所能到达的'.'的数目,'#'不可走,@本身算1个点。 思路:搜索入门题。
130 0
|
机器学习/深度学习
HDOJ/HDU 1556 Color the ball(树状数组)
HDOJ/HDU 1556 Color the ball(树状数组)
90 0
HDOJ 1312 (POJ 1979) Red and Black
HDOJ 1312 (POJ 1979) Red and Black
97 0
|
Java 机器学习/深度学习
HDU 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18404    Accepted Submission(s...
817 0
poj-1046-color me less
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 jus...
933 0
|
人工智能 网络协议
HDOJ 1312 (POJ 1979) Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black.
1094 0

热门文章

最新文章