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

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

Posted by 948142658 at 2012-06-09 02:14:01 on Problem 1046
In Reply To:帮个忙,浪费你几分钟,帮忙看看,是不是我理解错了题目 Posted by:948142658 at 2012-06-09 01:35:56
#include<math.h>
#include<iostream>
using namespace std;
#define N 10000
int main()
{
	int R[N],G[N],B[N],flag=0;
	int D=0;
	int i=0,j=0,k=0;
	int temp;
	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=(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++)
		{
		temp=(R[j]-R[k])*(R[j]-R[k])+(G[j]-G[k])*(G[j]-G[k])+(B[j]-B[k])*(B[j]-B[k]);
			if (D>temp)//存在最小的,交换
			{
				D=temp;
				flag=k;//修改标志
			}
		}
		cout<<"("<<R[j]<<","<<G[j]<<","<<B[j]<<") maps to ("<<R[flag]<<","<<G[flag]<<","<<B[flag]<<")"<<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