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 |
测试数据全部正确,为什么还是WA了,麻烦高手指点#include <iostream> #include <cmath> using namespace std; struct color { int R; int G; int B; }; double D(color cl1,color cl2) { double d = (cl1.R-cl2.R)*(cl1.R-cl2.R) + (cl1.G-cl2.G)*(cl1.G-cl2.G) + (cl1.B-cl2.B)*(cl1.B-cl2.B); return sqrt(d); } void main() { color clr[16]; for(int i=0;i<16;i++) { cin>>clr[i].R>>clr[i].G>>clr[i].B; } color test; cin>>test.R>>test.G>>test.B; while(test.R != -1){ int minMark=0; double min = D(clr[0],test); for(i=1;i<16;i++) { if( D(clr[i],test) <= min ) { min = D(clr[i],test); minMark = i; } } cout<<"("<<test.R<<","<<test.G<<","<<test.B<<")"<<" maps to (" <<clr[minMark].R<<","<<clr[minMark].G<<","<<clr[minMark].B<<")"<<endl; cin>>test.R>>test.G>>test.B; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator