Saturday, May 31, 2014

Topcoder High School SRM 5 250 pt - Level one - TV Size problem solution

Topcoder High School SRM 5 250 pt - Level one - TV Size problem statement: http://community.topcoder.com/stat?c=problem_statement&pm=6486&rd=10057

Topcoder High School SRM 5 250 pt - Level one - TV Size problem editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm5

Topcoder High School SRM 5 250 pt - Level one - TV Size problem solution: 

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

class TVSize {
    public: vector <int> calcSize(int d, int h, int w) {
        double a, r;
        vector <int> v;
        a=(double)sqrt(h*h + w*w);
        r=(double)d/a;
        v.push_back(h*r), v.push_back(w*r);
        return v;
    }
};

note: i suggest you to use (double), otherwise you won't get expected result. without (double) my prog returned 36, 64 instead of 25, 45 for sample 0. peek other AC codes also.

No comments:

Post a Comment