Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个我的c++代码,供参考

Posted by miaozishao at 2011-10-19 11:31:59 on Problem 1046
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator