POJ 1046
来源:互联网 发布:打蛋器价格淘宝 编辑:程序博客网 时间:2024/05/29 08:06
//实质就是让你求离在空间直角坐标系中某个给定的点的距离最近的那个点的坐标,即所谓的map(映射)
//注意:If there are more than one color with the same smallest distance,
//please output the color given first in the color set.
#include<iostream>
using namespace std;
int f(int a, int b, int c)
{
return a*a + b*b + c*c;
}
struct color
{
int R;
int G;
int B;
}c[16];
int main()
{
int x, y, z, i, m, n, l,min; //min记录所求的点的索引值(数组元素下标)
for (i = 0; i < 16; i++)
{
cin >> x >> y >> z;
c[i].R = x;
c[i].G = y;
c[i].B = z;
}
while (cin >> m >> n >> l&&!((m == -1) && (n == -1) && (l == -1)))
{
min = 0;
for (i = 1; i < 16; i++)
{
if (f(m - c[i].R, n - c[i].G, l - c[i].B) < f(m - c[min].R, n - c[min].G, l - c[min].B)) min = i;
}
cout << "(" << m << "," << n << "," << l << ") maps to (" << c[min].R << "," << c[min].G << "," << c[min].B << ")\n";
}
return 0;
}
//注意:If there are more than one color with the same smallest distance,
//please output the color given first in the color set.
#include<iostream>
using namespace std;
int f(int a, int b, int c)
{
return a*a + b*b + c*c;
}
struct color
{
int R;
int G;
int B;
}c[16];
int main()
{
int x, y, z, i, m, n, l,min; //min记录所求的点的索引值(数组元素下标)
for (i = 0; i < 16; i++)
{
cin >> x >> y >> z;
c[i].R = x;
c[i].G = y;
c[i].B = z;
}
while (cin >> m >> n >> l&&!((m == -1) && (n == -1) && (l == -1)))
{
min = 0;
for (i = 1; i < 16; i++)
{
if (f(m - c[i].R, n - c[i].G, l - c[i].B) < f(m - c[min].R, n - c[min].G, l - c[min].B)) min = i;
}
cout << "(" << m << "," << n << "," << l << ") maps to (" << c[min].R << "," << c[min].G << "," << c[min].B << ")\n";
}
return 0;
}
阅读全文
0 0
- POJ-1046
- POJ 1046
- POJ 1046
- POJ-1046
- poj 1046
- poj 1046
- POJ-1046
- POJ-1046
- POJ 1046
- poj 1046
- POJ 1046 解题报告
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- sql 2008 远程过程调用失败 0x800706be
- win7 postman 创建快捷方式
- Laboratory for Web Algorihmics数据集格式转换
- Session与Ajax
- 设计模式(Design Pattern)
- POJ 1046
- nginx之 [error] 6702#0:XXX is forbidden (13: Permission denied)
- Java:String、StringBuffer和StringBuilder的区别
- C语言作业-6-2完数
- hadoop-错误总结
- jq $.ajax POST/GET 向服务器传值问题
- Java之Spring框架入门示例!
- poj 1845
- 303. Range Sum Query