-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1046.cc
51 lines (42 loc) · 1.06 KB
/
1046.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Name: Color Me Less
//Level: 1
//Category: やるだけ
//Note:
/*
* やるだけ。3次元ベクトルの距離。
*/
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct Color {
int r, g, b;
};
int distance2(const Color &c1, const Color &c2) {
return pow(c1.r-c2.r, 2) + pow(c1.g-c2.g, 2) + pow(c1.b-c2.b, 2);
}
ostream& operator<< (ostream &os, const Color &c) {
os << "(" << c.r << "," << c.g << "," << c.b << ")";
return os;
}
int main() {
vector<Color> colors(16);
for(int i = 0; i < 16; ++i)
cin >> colors[i].r >> colors[i].g >> colors[i].b;
while(true) {
Color c;
cin >> c.r >> c.g >> c.b;
if(c.r == -1 && c.g == -1 && c.b == -1) break;
int mindist = 65536*3;
int bestidx = 0;
for(int i = 0; i < 16; ++i) {
int d = distance2(c, colors[i]);
if(d < mindist) {
mindist = d;
bestidx = i;
}
}
cout << c << " maps to " << colors[bestidx] << endl;
}
return 0;
}