Thursday, August 30, 2012

Topcoder SRM 552 Div 2 250 Problem



#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
 
using namespace std;
 
class FoxAndFlowerShopDivTwo {
public:
        int theMaxFlowers(vector <string>, int, int);
};
 
int get_flower_count(vector <string>& flowers,int x1,int y1,int x2,int y2)
{
        int count = 0;
        for(int i=x1;i<=x2;++i)
        {
                for(int j=y1;j<=y2;++j)
                {
                        if(flowers[i][j] == 'F')
                                count++;
                }
        }
        return count;
}
int FoxAndFlowerShopDivTwo::theMaxFlowers(vector <string> flowers, int r, int c) {
        
        int max_row = flowers.size()-1;
        int max_col = flowers[0].size()-1;
        
        int temp,max_flower = 0;
        if( c-1>=0)
        {
                temp = get_flower_count(flowers,0,0,max_row,c-1);
                if(temp > max_flower)
                        max_flower = temp;
        }
        if(r-1 >= 0)
        {
                temp = get_flower_count(flowers,0,0,r-1,max_col);
                if(temp > max_flower)
                        max_flower = temp;
        }
        if(r+1 <= max_row)
        {
                temp = get_flower_count(flowers,r+1,0,max_row,max_col);
                if(temp > max_flower)
                        max_flower = temp;
        }
        if(c+1 <= max_col)
        {
                temp = get_flower_count(flowers,0,c+1,max_row,max_col);
                if(temp > max_flower)
                        max_flower = temp;
        }
        return max_flower;      
}

No comments:

Post a Comment