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 03:06:42 on Problem 1046 and last updated at 2012-06-09 04:26:01
In Reply To:帮个忙,浪费你几分钟,帮忙看看,是不是我理解错了题目 Posted by:948142658 at 2012-06-09 01:35:56
#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;
	while (cin>>R[i]>>G[i]>>B[i],R[i]!=-1&&G[i]!=-1&&B[i]!=-1) 
	{
	//	
		j=i;
		if (j>=16)
		{ 
			D=(R[j]-R[0])*(R[j]-R[0])+(G[j]-G[0])*(G[j]-G[0])+(B[j]-B[0])*(B[j]-B[0]);	
			//flag=k;
			for (flag=k=0;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;
		}	
		i++;
	}
	return 0;
}
终于好了,错在少了一个flag=k;

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