POJ 1046

#include<stdio.h>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int test = 16;
struct color{
	 int RGB[3];
};
 bool comp(float d1, float d2){
 	return (d1<d2);
 }
double count(color& colorDic, color& c){
	double R = abs(colorDic.RGB[0] - c.RGB[0]);
    double G = abs(colorDic.RGB[1] - c.RGB[1]);
	double B = abs(colorDic.RGB[2] - c.RGB[2]);
	return sqrt( R*R + G*G +B*B	);
}
int main(){
	int n, len;
	vector<color> vc;
    vector<float> r;
	int r1, r2, r3;
	scanf("%d%d%d",&r1, &r2,&r3);
	while(-1 != r1 && -1 != r2 && -1 !=r3){
		color c;
		c.RGB[0] = r1;
		c.RGB[1] = r2;
		c.RGB[2] = r3;
		vc.push_back(c);
		scanf("%d%d%d",&r1, &r2,&r3);
	}
	for (int i =test; i < vc.size(); i++)
	{
		for (int j =0 ; j< test;j++)
		{
			float res =count(vc[j],vc[i] );
			r.push_back(res);
		}
		vector<float>::iterator rr = min_element(r.begin(), r.end(), comp);
		int dd = rr - r.begin();
		printf("(%d,%d,%d) maps to (%d,%d,%d)\n", vc[i].RGB[0], vc[i].RGB[1],vc[i].RGB[2],
		vc[dd].RGB[0], vc[dd].RGB[1], vc[dd].RGB[2]
			);
		r.clear();
	}

	return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值