ZOJ-1067 基本运算题

1067:给出16种RGB值作为基准,将后来的颜色值映射到距离最近的颜色。
距离的定义为

[img]http://dl.iteye.com/upload/attachment/535836/5a7b96b5-aa22-31a7-ab2d-3999293b3709.gif[/img]

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)


简单题。依次计算找距离最小即可。


#include<stdio.h>
#include<iostream>
using namespace std;

int color[16][3];
int main()
{
int R,G,B;
int index;
int diff;
int cal;

//目标颜色
for(int i=0;i<16;i++)
{
cin>>color[i][0];
cin>>color[i][1];
cin>>color[i][2];
}

while(1)
{
index=-1;
diff=-1;
cin>>R;
cin>>G;
cin>>B;

if(R==-1&&G==-1&&B==-1)
break;

for(int i=0;i<16;i++)
{
cal=(R-color[i][0])*(R-color[i][0])+(G-color[i][1])*(G-color[i][1])+(B-color[i][2])*(B-color[i][2]);
if(diff==-1||cal<diff)
{
diff=cal;
index=i;
}
}

printf("(%d,%d,%d) maps to (%d,%d,%d)\n",R,G,B,color[index][0],color[index][1],color[index][2]);

}



}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值