ZOJ Problem Set - 1067
来源:互联网 发布:cisco 查看端口模式 编辑:程序博客网 时间:2024/04/28 08:00
ZOJ Problem Set - 1067
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=67
没想出什么好的算法,直接写代码了,没什么优化。
#include <iostream>
#include <climits>
using namespace std;
#include <math.h>
int main()
{
int tarSet[16][3];
int Color[3];
int loop = 0;
long dist, minDist, minIdx;
while(16 > loop) {
cin >> tarSet[loop][0]
>> tarSet[loop][1]
>> tarSet[loop][2];
loop++;
}
while(cin >> Color[0] >> Color[1] >> Color[2]) {
if(-1 == Color[0] && -1 == Color[1] && -1==Color[2])
break;
minDist = INT_MAX;
minIdx = -1;
for(loop = 0;loop < 16;loop++) {
dist = (tarSet[loop][0] - Color[0]) * (tarSet[loop][0] - Color[0])
+ (tarSet[loop][1] - Color[1]) * (tarSet[loop][1] - Color[1])
+ (tarSet[loop][2] - Color[2]) * (tarSet[loop][2] - Color[2]);
if(dist < minDist) {
minDist = dist;
minIdx = loop;
}
}
cout << "(" << Color[0] << ","
<< Color[1] << ","
<< Color[2] << ") maps to ("
<< tarSet[minIdx][0] << ","
<< tarSet[minIdx][1] << ","
<< tarSet[minIdx][2] << ")"
<< endl;
}
return 0;
}
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1067 Color Me Less
- ZOJ Problem Set - 1067 Color Me Less
- ZOJ Problem Set - 1067||Color Me Less
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1115
- ZOJ Problem Set - 1151
- ZOJ Problem Set - 1205
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 1029
- ZOJ Problem Set - 1076
- ZOJ Problem Set - 1117
- 辗转相除法
- 今天遇到了难题,希望解决
- static 关键字
- 怎样做一块好的PCB板
- Y450调整显示器亮度
- ZOJ Problem Set - 1067
- ZOJ 1700 Falling Leaves
- c# 如何编写组建之访问组建的容器
- Spring 3.0.5 发布,J2EE框架
- VB中MsFlexGrid控件的使用细则
- c 语法部分补充2
- 打印控件更新至1,1,0,151版本(更新批量打印bug)
- 配置
- 2440 linux 串口驱动编写(大内密探)