Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮个忙,浪费你几分钟,帮忙看看,是不是我理解错了题目#include<math.h> #include<iostream> using namespace std; #define N 10000 int main() { int R[N],G[N],B[N],flag=0; double D[N]={0}; int i=0,j=0,k=0; do {cin>>R[i]>>G[i]>>B[i]; i++; } while (R[i-1]!=-1&&G[i-1]!=-1&&B[i-1]!=-1); for (j=16;j<i-1;j++)//从第 17 个开始,一个一个输出 { D[j]=sqrt((R[j]-R[0])*(R[j]-R[0])+(G[j]-G[0])*(G[j]-G[0])+(B[j]-G[0])*(B[j]-G[0]));//假设为第一个 for (k=1;k<16;k++) { double temp=sqrt((R[j]-R[k])*(R[j]-R[k])+(G[j]-G[k])*(G[j]-G[k])+(B[j]-G[k])*(B[j]-G[k])); if (D[j]>temp)//存在最小的,交换 { D[j]=temp; flag=k;//修改标志 } } cout<<"("<<R[j]<<","<<G[j]<<","<<B[j]<<") maps to ("<<R[flag]<<","<<G[flag]<<","<<B[flag]<<")"<<endl; } return 0; } 是不是从前面16 个中找到最小的距离的那个? Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator