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 |
这道题唯一的乐趣......In Reply To:有硕士博士吗,同等学力的也进来帮帮我,为什么VC能通过提交总是wrong anwser Posted by:winter_1 at 2006-04-23 22:22:27 #include<iostream> #include<vector> #include<cmath> using namespace std; class RGB{ public: RGB(const float r,const float g, const float b): R(r),G(g),B(b){}; float R; float G; float B; }; istream& operator>>( istream& is, RGB &t){ is >> t.R >> t.G >> t.B; return is; } double Distance( const RGB &a, const RGB &b){ return sqrt( (a.R-b.R)*(a.R-b.R) + (a.G-b.G)*(a.G-b.G) + (a.B-b.B)*(a.B-b.B) ); } int main() { double distance, tem; int ans; vector<RGB> target(17,RGB(0,0,0)); for (int i = 1; i <= 16; ++i){ cin >> target[i]; } RGB ins(0,0,0); while (cin >> ins, ins.R != -1){ distance = Distance( ins, target[1]); ans = 1; for (int i = 2; i <= 16; ++i){ tem = Distance( ins, target[i]); if (distance > tem){ distance = tem; ans = i; } } cout << "("<<ins.R<<","<<ins.G<<","<<ins.B<<")" << " maps to " << "("<<target[ans].R<<","<<target[ans].G<<","<<target[ans].B<<")" << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator