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 |
贴个我的c++代码,供参考#include <iostream> using namespace std; int main() { int i=0,r,g,v,b[50][3]={0},t,k,d1,min,e; while (cin>>r>>g>>v) { if (r==-1&&g==-1&&v==-1) break;//输入限制 b[i][0]=r;b[i][1]=g;b[i][2]=v; //存储输入的数据 i++; } for (t=i-(i-15)+1;t<i;t++)//比较距离 { min=5215076; for (k=0;k<16;k++) { d1=(b[t][0]-b[k][0])*(b[t][0]-b[k][0])+(b[t][1]-b[k][1])*(b[t][1]-b[k][1])+(b[t][2]-b[k][2])*(b[t][2]-b[k][2]); if(d1<min) { min=d1; e=k; } } cout<<"("<<b[t][0]<<","<<b[t][1]<<","<<b[t][2]<<") maps to ("<<b[e][0]<<","<<b[e][1]<<","<<b[e][2]<<")"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator