Пример #1
0
int main()	{
	int before[7] = {0, };
	int after[7] = {0, };
	int nextPodo, n, i, result = 0;
	
	scanf(" %d", &n);
	
	if( n == 1 ) {
		// If n == 1, just return first value.
		scanf(" %d", &nextPodo);
		result = nextPodo;
	}
	else if( n == 2 )	{
		// If n is 2, just add all is largest.
		scanf(" %d", &nextPodo);
		result += nextPodo;

		scanf(" %d", &nextPodo);
		result += nextPodo;
	}
	else {
		scanf(" %d", &nextPodo);
		before[0] += nextPodo;
		before[1] += nextPodo;
		before[2] += nextPodo;

		scanf(" %d", &nextPodo);
		before[0] += nextPodo;
		before[3] += nextPodo;
		before[4] += nextPodo;

		scanf(" %d", &nextPodo);
		before[1] += nextPodo;
		before[4] += nextPodo;
		before[5] += nextPodo;

		for(i = 3; i < n; i++)	{
			scanf(" %d", &nextPodo);
			calcNext(before, after, nextPodo);
		}
		for(i = 0; i < 7; i++)	{
			if(result < before[i]) result = before[i];
		}
	}

	printf("%d", result);

	return 0;
}
Пример #2
0
void threadResumeNext() { // Funcao que resume o processamento de uma thread
	if (pthread_mutex_lock(&mutex) != 0) {
		perror("pthread_mutex_lock()");
		exit(EXIT_FAILURE);
	}
	flags[next] = 1;
	calcNext();
	if (pthread_cond_signal(&cond) != 0) {
		perror("pthread_cond_signal()");
		exit(EXIT_FAILURE);
	}
	if (pthread_mutex_unlock(&mutex) != 0) {
		perror("pthread_mutex_unlock()");
		exit(EXIT_FAILURE);
	}
}
Пример #3
0
KRecordList *IntervalCPU::init( TRecordTime initialTime, TCreateList create,
                                KRecordList *displayList )
{
  createList = create;
  currentValue = 0.0;
  currentInitialTime = initialTime;

  if( displayList == NULL )
  {
    displayList = &myDisplayList;
    displayList->clear();
  }

  function = ( SemanticCPU * ) window->getSemanticFunction( level );
  if( functionThread != NULL ) delete functionThread;
  functionThread = ( SemanticThread * ) window->getSemanticFunction( THREAD )->clone();
  if( functionComposeThread != NULL ) delete functionComposeThread;
  functionComposeThread = ( SemanticCompose * ) window->getSemanticFunction( COMPOSETHREAD )->clone();

  if( begin != NULL )
    delete begin;
  if( end != NULL )
    delete end;

  if( initialTime >= window->getTrace()->getEndTime() )
  {
    begin = window->getCPUEndRecord( order - 1 );
    end = begin->clone();
    return displayList;
  }

  if( intervalCompose.empty() )
  {
    begin = window->getCPUBeginRecord( order - 1 )->clone();
    end = window->getCPUEndRecord( order - 1 )->clone();
    return displayList;
  }


  for( std::vector<IntervalThread *>::iterator it = intervalThread.begin();
       it != intervalThread.end(); ++it )
  {
    if( (*it) != NULL )
      (*it)->setSemanticFunction( functionThread );
  }

  for( std::vector<IntervalCompose *>::iterator it = intervalCompose.begin();
       it != intervalCompose.end(); ++it )
  {
    if( (*it) != NULL )
    {
      (*it)->setSemanticFunction( functionComposeThread );
      (*it)->init( initialTime, NOCREATE, NULL );
    }
  }

  begin = window->getCPURecordByTime( order - 1 )->clone();
  end = begin->clone();

  if(( !function->getInitFromBegin() ) && ( !functionThread->getInitFromBegin() ) &&
      ( !functionComposeThread->getInitFromBegin() ) && ( initialTime > 0.0 ) )
    calcPrev( displayList, true );

  calcNext( displayList, true );
  while(( !end->isNull() ) && ( end->getTime() <= initialTime ) )
    calcNext( displayList );

  return displayList;
}
Пример #4
0
KRecordList *IntervalCompose::init( TRecordTime initialTime, TCreateList create,
                                    KRecordList *displayList )
{
  TRecordTime myInitTime;
  SemanticHighInfo info;
  info.callingInterval = this;

  createList = create;
  currentValue = 0.0;

  if ( displayList == NULL )
  {
    displayList = &myDisplayList;
    displayList->clear();
  }

  if( !notWindowInits )
    function = ( SemanticCompose * ) window->getSemanticFunction( level );

  if ( endRecord != NULL )
  {
    delete endRecord;
    endRecord = NULL;
  }
  if ( beginRecord != NULL )
  {
    delete beginRecord;
    beginRecord = NULL;
  }

  if ( typeid( *function ) == typeid( ComposeJoinBursts ) )
  {
    joinBursts = true;
    endRecord = ( ( KSingleWindow * ) window )->getEndRecord();
    beginRecord = ( ( KSingleWindow * ) window )->getBeginRecord();
  }
  else
  {
    joinBursts = false;
  }

  if( !notWindowInits )
    setChilds();

  if ( function->getInitFromBegin() )
    myInitTime = 0.0;
  else
    myInitTime = initialTime;

  childIntervals[ 0 ]->init( myInitTime, create, displayList );

  if( begin != NULL && begin != beginRecord )
    delete begin;
  begin = childIntervals[ 0 ]->getBegin()->clone();

  if( end != NULL )
    delete end;
  end = childIntervals[ 0 ]->getEnd()->clone();

  if ( joinBursts )
  {
    TSemanticValue tmpValue;
    MemoryTrace::iterator *lastEnd = endRecord;

    tmpValue = childIntervals[ 0 ]->getValue();
    childIntervals[ 0 ]->calcNext( displayList );
    while ( tmpValue == childIntervals[ 0 ]->getValue() )
    {
      if( end != NULL )
        delete end;
      end = childIntervals[ 0 ]->getEnd()->clone();

      // somehow, this break never is executed
      // if ( *end == *endRecord )
      if (( *end == *endRecord ) || ( *end == *lastEnd ))
        break;

      // lastEnd to control loop!
      if( lastEnd != NULL && lastEnd != endRecord )
        delete lastEnd;
      lastEnd = end->clone();

      childIntervals[ 0 ]->calcNext( displayList );
    }
    currentValue = tmpValue;
    if( lastEnd != NULL && lastEnd != endRecord )
      delete lastEnd;
  }
  else
  {
    info.values.push_back( childIntervals[ 0 ]->getValue() );
    currentValue = function->execute( &info );
  }

  if ( function->getInitFromBegin() )
  {
    while ( end->getTime() <= initialTime )
      calcNext( displayList );
  }

  return displayList;
}
Пример #5
0
KRecordList *IntervalDerived::init( TRecordTime initialTime, TCreateList create,
                                   KRecordList *displayList )
{
  TRecordTime myInitTime;
  info.values.clear();
  info.callingInterval = this;

  createList = create;
  currentValue = 0.0;

  if ( displayList == NULL )
  {
    displayList = &myDisplayList;
    displayList->clear();
  }

  function = ( SemanticDerived * ) window->getSemanticFunction( level );

  setChilds();

  if ( begin != NULL )
  {
    delete begin;
    begin = NULL;
  }
  if ( end != NULL )
  {
    delete end;
    end = NULL;
  }

  if ( function->getInitFromBegin() )
    myInitTime = 0.0;
  else
    myInitTime = initialTime;

  info.callingInterval = this;

  for ( TObjectOrder i = 0; i < childIntervals.size(); i++ )
  {
    childIntervals[ i ]->init( myInitTime, createList, displayList );

    if ( begin == NULL ||
         childIntervals[ i ]->getBegin()->getTime() > begin->getTime() )
    {
      if ( begin != NULL )
        delete begin;
      begin = childIntervals[ i ]->getBegin()->clone();
    }

    if ( end == NULL ||
         childIntervals[ i ]->getEnd()->getTime() < end->getTime() )
    {
      if ( end != NULL )
        delete end;
      end = childIntervals[ i ]->getEnd()->clone();
    }

    info.values.push_back( childIntervals[ i ]->getValue() *
                           window->getFactor( i ) );
  }
  currentValue = function->execute( &info );

  while ( end->getTime() < initialTime )
    calcNext( displayList );

  return displayList;
}