Monday, June 9, 2014

Topcoder High School SRM 11 250 pt - Level one - City Buses solution

Topcoder High School SRM 11 250 pt - Level one - City Buses statement: http://community.topcoder.com/stat?c=problem_statement&pm=6388&rd=10063

Topcoder High School SRM 11 250 pt - Level one - City Buses editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm11

Topcoder High School SRM 11 250 pt - Level one - City Buses solution:

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

class CityBuses {
    public: int maximumFare(vector <string> v) {
        int ma=0;
        for(int i=0; i<v.size(); i++) {
            for(int j=0; j<v[i].length(); j++) {
                if(v[i][j]=='B') {
                    for(int k=0; k<v.size(); k++) {
                        for(int l=0; l<v[i].length(); l++) {
                            if(v[k][l]=='B') {
                                if(abs(i-k)+abs(j-l)>ma) ma=abs(i-k)+abs(j-l);
                            }
                        }
                    }
                }
            }
        }
        return ma;
    }
};

note: after compiling i tested my code on examples and it returned expected results except last example, example 3. no matter what, i got AC.
for details: http://apps.topcoder.com/forums/?module=Thread&threadID=821317&start=0&mc=1#1887528

No comments:

Post a Comment