All pastes #290796 Raw Edit

Unnamed

public text v1 · immutable
#290796 ·published 2006-12-24 11:06 UTC
rendered paste body
#include <iostream>
#include <vector>

using namespace std;

class StairClimb
{
public:
   int stridesTaken(vector <int> ff, int ss);
};
int StairClimb::stridesTaken(vector<int> ff,int ss)
{
	int s = ff.size();
	int res = 2*(s-1);
	for(int i=0; i<s; i++)
	  if(ff[i]%ss == 0) res = res + ff[i]/ss;
	  else res = res + ff[i]/ss + 1;
	return res;
}


Problem Statement
    
You are climbing a staircase. The staircase consists of some number of flights of stairs separated by landings. A flight is a a continuous series of stairs from one landing to another. You are a reasonably tall athletic person, so you can climb a certain number of stairs in one stride. However, after each flight, there is a landing which you cannot skip because you need to turn around for the next flight (which continues in the opposite direction).
You will be given the number of stairs in each flight in a vector <int> flights. Element 0 of flights represents the number of stairs in the first flight, element 1 is the number of stairs in the second flight, etc. You will also be given an int stairsPerStride, which is how many continuous stairs you climb in each stride. If it takes two strides to turn around at a landing, return the number of strides to get to the top of the staircase. You do not need to turn at the top of the staircase.
Definition
    
Class:
StairClimb
Method:
stridesTaken
Parameters:
vector <int>, int
Returns:
int
Method signature:
int stridesTaken(vector <int> flights, int stairsPerStride)
(be sure your method is public)
    

Constraints
-
flights has between 1 and 50 elements, inclusive.
-
Each element of flights is between 5 and 30, inclusive.
-
stairsPerStride is between 2 and 5, inclusive.
Examples
0)

    
{15}
2
Returns: 8
A simple staircase with 15 steps. In 7 strides, you've climbed 14 steps. However, you still have one step left, so you must use an additional stride to get to the top.
1)

    
{15,15}
2
Returns: 18
This time, there are two flights with a landing in between. 8 strides to get to the first landing, 2 strides to turn around, and 8 more strides to get to the top makes 8+2+8=18 strides.
2)

    
{5,11,9,13,8,30,14}
3
Returns: 44

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.