Пример #1
0
long countSteps(int steps){

	if (steps < 0) return 0;
	if (steps == 0) return 1;

	return countSteps(steps-1) + countSteps(steps-2) + countSteps(steps-3);
}
Пример #2
0
double KSimExponentStep::next(double value) const
{
	tParts part;
	double res;
	if(countSteps() && findPart(value, part))
	{
		if (part.result > value)
		{
			res = part.result;
		}
		else if(part.factorIndex < stepList.count()-1)
		{
			res = convert (part.factorIndex+1,part.exponent);
		}
		else
		{
			res = convert (0,part.exponent+1);
		}
	}
	else
	{
		res = value;
	}
	return res;
}
Пример #3
0
double KSimExponentStep::previous(double value) const
{
	tParts part;
	double res;
	
	if(countSteps() && findPart(value, part))
	{
		if (part.result < value)
		{
			res = part.result;
		}
		else if(part.factorIndex > 0)
		{
			res = convert (part.factorIndex-1,part.exponent);
		}
		else
		{
			res = convert (stepList.count()-1,part.exponent-1);
		}
	}
	else
	{
		res = value;
	}
	return res;
}
Пример #4
0
void Foo::resetSteps()
{
	// resets all step counts to zero for a certain foo.
	
	stepIndex = 0;
	theCurrentStep = steps.entry(stepIndex)->me;
	for (int n=0;n<countSteps();n++)
	{
		steps.entry(n)->me->currentCount	= 0;
		steps.entry(n)->me->isFinished		= false;
	}
}
Пример #5
0
double KSimExponentStep::adjust(double value) const
{
	tParts part;
	if(countSteps() && findPart(value, part))
	{
		return part.result;
	}
	else
	{
		return value;
	}
}
Пример #6
0
int main(int argc, char* argv[]){

	int n = 1;
	long res;
 
	if ( argc > 1 )
		n = atol(argv[1]);

	res = countSteps(n);
	printf("For n=%d, there are %ld ways.\n", n, res);

	return 0;
}
Пример #7
0
void Foo::checkSteps()
{
	// checks steps to see whether they have run their course.
	// if a step is done running, next step is selected as current.
	
	theCurrentStep = steps.entry(stepIndex)->me;
	
	if (theCurrentStep->isFinished)
	{
		stepIndex++;
		
		if (stepIndex == countSteps())
		{
			if (repeats)	resetSteps();
			else			isRunning = false;
		}
		else
		{
			theCurrentStep = steps.entry(stepIndex)->me;
		}
	}
}
Пример #8
0
uint16_t stepDetector(pedometer_data_t data[], uint16_t dataLen) {
	
  // Create new data object to contained normalized value
  fixed_t* normData = malloc(dataLen*sizeof(fixed_t));
  uint16_t i;
  for (i = 0; i < dataLen; i++) {

    // Norm is simply sum of squares, do not take sqrt for precision purposes and
    //  also subtract gravity
    normData[i] = sumSqrs(data[i]) - GRAVITY_OFFSET;
  }

  // Filter data with band pass filter, note modifies normData
  bandpassFilter(normData, dataLen);

  // Count and return steps
  uint16_t nSteps = countSteps(normData, dataLen);

  // Clean-up memory
  free(normData);

  return nSteps;
}
Пример #9
0
int main(void){
	int i;

	scanf("%d", &N);

	for (i = 1; i < N; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		addEdge(a,b,graph,&nextEdge,start);
		addEdge(b,a,graph,&nextEdge,start);
	}

	for (i = 1; i <= N; i++)
		scanf("%lld", &value[i]);

	buildTree(1,-1);

	countSteps(1);

	printf("%lld\n", increment[1] + decrement[1]);

	return 0;
}
Пример #10
0
void countSteps(int n){
	int i;

	if (isLeaf[n]){
		if (value[n] > 0)
			decrement[n] = value[n];
		else
			increment[n] = -value[n];
		return;
	}

	for (i = cStart[n]; i; i = children[i].next){
		countSteps(children[i].node);
		increment[n] = max(increment[n], increment[children[i].node]);
		decrement[n] = max(decrement[n], decrement[children[i].node]);
	}

	long long int diff = increment[n] - decrement[n] + value[n];

	if (diff > 0)
		decrement[n] += diff;
	else
		increment[n] += -diff;
}
Пример #11
0
bool Foo::hasSteps()
{
	if (countSteps())	return 1;
	else				return 0;
}