首页 > 其他 > 详细

Color Me Less

时间:2014-08-19 10:59:54      阅读:339      评论:0      收藏:0      [点我收藏+]

/*Color Me Less
Language:DefaultColor Me Less
Time Limit: 1000MS  Memory Limit: 10000K
Total Submissions: 30337  Accepted: 14746

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)

*/
//题意就是先输入16个点的坐标,然后输入点,求输入点与16个点钟最短距离,如果距离相等,输出靠前的点的坐标。
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a[20],b[20],c[20];
double d[20];
int main()
{
    int i,j,v;
    double t,max;
    for(i=0;i<16;i++)
    scanf("%d %d %d",&a[i],&b[i],&c[i]);
    int m,n,k,l;
    while(~scanf("%d %d %d",&m,&n,&k)&&(m!=-1||n!=-1||k!=-1))
    {
        double d[20]={0};
        for(i=0;i<16;i++)
        d[i]=sqrt((m-a[i])*(m-a[i])+(n-b[i])*(n-b[i])+(k-c[i])*(k-c[i]));
        for(i=0;i<16;i++)
        {
            for(j=i+1;j<16;j++)
            if(d[i]<d[j])
            {
                t=d[i];
                d[i]=d[j];
                d[j]=t;
                v=a[i];
                a[i]=a[j];
                a[j]=v;
                v=b[i];
                b[i]=b[j];
                b[j]=v;
                v=c[i];
                c[i]=c[j];
                c[j]=v;
            }
        }
        max=d[15];
        for(i=0;i<16;i++)
        {
            if(d[i]==d[15])
            l=i;
            continue;
        }
        printf("(%d,%d,%d) maps to (%d,%d,%d)",m,n,k,a[l],b[l],c[l]);
        printf("\n");
    }
    //while(1);
    return 0;
}       
       
       
       

Color Me Less,布布扣,bubuko.com

Color Me Less

原文:http://blog.csdn.net/hdd871532887/article/details/38678057

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!