All pastes #952877 Raw Edit

Unnamed

public text v1 · immutable
#952877 ·published 2008-03-22 16:42 UTC
rendered paste body
#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 MountainWalk {
public:
	int cellsVisited(vector <string>, int);
	int abs(int);
};

int MountainWalk::cellsVisited(vector <string> areaMap, int h) 
{
	int row = areaMap.size();
	int col = areaMap[0].size();
	
	int i = 0;
	int j = 0;
	int ans = 1;
	vector < vector <bool> > maps(row, vector <bool>(col,false));

	maps[0][0] = true;
	while(true)
	{
		if((i < row-1) && (maps[i+1][j] == false) && abs(areaMap[i][j]-areaMap[i+1][j]) <= h)
		{		
			i = i+1;
			maps[i][j] = true;
			ans++;
			cout<<i<<" "<<j<<endl;
		}
		else if((j != 0) && (maps[i][j-1] == false) && abs(areaMap[i][j]-areaMap[i][j-1]) <= h)
		{
			j = j-1;
			maps[i][j] = true;
			ans++;
			cout<<i<<" "<<j<<endl;
		}
		else if((i != 0) && (maps[i-1][j] == false) && abs(areaMap[i][j]-areaMap[i-1][j]) <= h)
		{
			i = i-1;
			maps[i][j] = true;
			ans++;
			cout<<i<<" "<<j<<endl;
		}
		else if((j < col-1) && (maps[i][j+1] == false) && abs(areaMap[i][j]-areaMap[i][j+1]) <= h)
		{
			j = j+1;
			maps[i][j] = true;
			ans++;
			cout<<i<<" "<<j<<endl;
		}
		else
		{
			break;
		}
	}
	
	return ans;
}

int MountainWalk:: abs(int n)
{
	if(n >= 0)
		return n;
	else
		return (-n);
}