ZOJ-1067 Basics

Source: Internet
Author: User

1067: 16 RGB values are given as the reference, and the subsequent color values are mapped to the nearest color.

Distance is defined

 

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

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) maps to (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)

 

 

 

Simple question. Calculate the minimum distance in sequence.

 

C ++ code

# Include <stdio. h>

# Include <iostream>

Using namespace std;

 

Int color [16] [3];

Int main ()

{

Int R, G, B;

Int index;

Int diff;

Int cal;

 

// Target color

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]);

 

}

 

 

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.