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

帮个忙,浪费你几分钟,帮忙看看,是不是我理解错了题目

Posted by 948142658 at 2012-06-09 01:35:56 on Problem 1046
#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:
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