inline void updateLoadInfo(int p_index, int possible_pe, double upper_threshold_temp, double lower_threshold_temp, std::vector<int>& parr_above_avg, std::vector<int>& parr_below_avg, std::vector<bool> &proc_load_info, ProcArray *parr) { ProcInfo& p = parr->procs[p_index]; ProcInfo& possible_pe_procinfo = parr->procs[possible_pe]; // If the updated load is still greater than the average by the // threshold value, then push it back to the max heap if (p.getTotalLoad() > upper_threshold_temp) { parr_above_avg.push_back(p_index); std::push_heap(parr_above_avg.begin(), parr_above_avg.end(), ProcLoadGreater(parr)); //CkPrintf("\t Pushing pe : %d to max heap\n", p.getProcId()); } else if (p.getTotalLoad() < lower_threshold_temp) { parr_below_avg.push_back(p_index); proc_load_info[p_index] = true; //CkPrintf("\t Adding pe : %d to less loaded\n", p.getProcId()); } // If the newly assigned processor's load is greater than the average // by the threshold value, then push it into the max heap. if (possible_pe_procinfo.getTotalLoad() > upper_threshold_temp) { // TODO: It should be the index in procarray :( parr_above_avg.push_back(possible_pe); std::push_heap(parr_above_avg.begin(), parr_above_avg.end(), ProcLoadGreater(parr)); removeFromArray(possible_pe, parr_below_avg); proc_load_info[possible_pe] = false; //CkPrintf("\t Pusing pe : %d to max heap\n", possible_pe); } else if (possible_pe_procinfo.getTotalLoad() < lower_threshold_temp) { } else { removeFromArray(possible_pe, parr_below_avg); proc_load_info[possible_pe] = false; //CkPrintf("\t Removing from lower list pe : %d\n", possible_pe); } }
int main() { srand(time(NULL)); for (int x = 0; x < std::rand() % 10 + 5; x++)//Crea un arreglo de tamaño aleatorio entre 5 y 10 { arreglo[x] = std::rand() % 100 + 1; //De 1 a 100 al azar currSize++; } std::cout << "Initialized new array of size " << currSize << std::endl; printArray(arreglo);//Imprime el arreglo for (int x = 0; x < addAmount; x++) addToArray(std::rand() % 100 + 1, std::rand() % 10, arreglo);//Agrega numero entre 1 y 100 a posicion entre 0 y 9 for (int x = 0; x < removeAmount; x++) removeFromArray(std::rand() % 10, arreglo);//Borra numero de posicion entre 0 y 9 return 0; }
int main() { int i, j, k; int maxIndex; double gradeSum; int participantsAmount; double participantScores[MAX_WIDTH]; double participantAverages[MAX_WIDTH]; int participantsClassfication[MAX_WIDTH]; double participantGrades[MAX_HEIGHT][MAX_WIDTH]; int participantPositions[MAX_HEIGHT][MAX_WIDTH]; scanf("%d", &participantsAmount); readField(participantGrades, MAX_HEIGHT, participantsAmount); /* Cálculo da Média */ for (j = 0; j < participantsAmount; j++) { gradeSum = participantGrades[0][j]; for (i = 1; i < MAX_HEIGHT; i++) { gradeSum += participantGrades[i][j]; } participantAverages[j] = gradeSum / MAX_HEIGHT; } { printf("Nota Media:"); for (j = 0; j < participantsAmount; j++) { printf(" %.1f", participantAverages[j]); } printf("\n"); printf("\n"); } /* Define a ordem inicial de classificação para cada jurado. */ for (i = 0; i < MAX_HEIGHT; i++) { for (j = 0; j < participantsAmount; j++) { participantPositions[i][j] = j; } insertionSort(&participantPositions[i][0], &participantGrades[i][0], participantsAmount); } { printf("Preferencia:\n"); for (i = 0; i < MAX_HEIGHT; i++) { printf("Membro %d:", i + 1); for (j = 0; j < participantsAmount; j++) { printf(" %d", participantPositions[i][j] + 1); } printf("\n"); } printf("\n"); } for (j = 0; j < participantsAmount; j++) { participantScores[j] = participantAverages[j]; } for (i = 0; i < MAX_HEIGHT; i++) { participantScores[participantPositions[i][0]] += 100; } for (k = 0; k < participantsAmount; k++) { maxIndex = 0; for (j = 1; j < participantsAmount; j++) { if (participantScores[maxIndex] < participantScores[j]) { maxIndex = j; } } participantsClassfication[k] = maxIndex; participantScores[maxIndex] = 0; for (i = 0; i < MAX_HEIGHT; i++) { if (participantPositions[i][0] == maxIndex) { if (participantsAmount - k > 1) { participantScores[participantPositions[i][1]] += 100; } } removeFromArray(&participantPositions[i][0], participantsAmount - k, maxIndex); } } { printf("Classificacao:"); for (j = 0; j < participantsAmount; j++) { printf(" %d", participantsClassfication[j] + 1); } printf("\n"); } return 0; }
int removeLastElementOfArray(Array *array, void *elem) { return removeFromArray(array, array->count-1, elem); }
int removeFirstElementOfArray(Array *array, void *elem) { return removeFromArray(array, 0, elem); }
//! Removes waste vertices from the specified data and shape static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, const QModelIndex & iShape ) { try { // read the data QVector<Vector3> verts = nif->getArray<Vector3>( iData, "Vertices" ); if ( ! verts.count() ) { throw QString( Spell::tr("no vertices?") ); } QVector<Vector3> norms = nif->getArray<Vector3>( iData, "Normals" ); QVector<Color4> colors = nif->getArray<Color4>( iData, "Vertex Colors" ); QList< QVector<Vector2> > texco; QModelIndex iUVSets = nif->getIndex( iData, "UV Sets" ); for ( int r = 0; r < nif->rowCount( iUVSets ); r++ ) { texco << nif->getArray<Vector2>( iUVSets.child( r, 0 ) ); if ( texco.last().count() != verts.count() ) throw QString( "uv array size differs" ); } int numVerts = verts.count(); if ( numVerts != nif->get<int>( iData, "Num Vertices" ) || ( norms.count() && norms.count() != numVerts ) || ( colors.count() && colors.count() != numVerts ) ) { throw QString( "vertex array size differs" ); } // detect unused vertices QMap<quint16, bool> used; QVector<Triangle> tris = nif->getArray<Triangle>( iData, "Triangles" ); foreach ( Triangle tri, tris ) { for ( int t = 0; t < 3; t++ ) used.insert( tri[t], true ); } QList< QVector< quint16 > > strips; QModelIndex iPoints = nif->getIndex( iData, "Points" ); for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) { strips << nif->getArray<quint16>( iPoints.child( r, 0 ) ); foreach ( quint16 p, strips.last() ) used.insert( p, true ); } // remove them qWarning() << "removing" << verts.count() - used.count() << "vertices"; if ( verts.count() == used.count() ) return; removeFromArray( verts, used ); removeFromArray( norms, used ); removeFromArray( colors, used ); for ( int c = 0; c < texco.count(); c++ ) removeFromArray( texco[c], used ); // adjust the faces QMap<quint16,quint16> map; quint16 y = 0; for ( quint16 x = 0; x < numVerts; x++ ) { if ( used.contains( x ) ) map.insert( x, y++ ); } QMutableVectorIterator<Triangle> itri( tris ); while ( itri.hasNext() ) { Triangle & tri = itri.next(); for ( int t = 0; t < 3; t++ ) if ( map.contains( tri[t] ) ) tri[t] = map[ tri[t] ]; } QMutableListIterator< QVector<quint16> > istrip( strips ); while ( istrip.hasNext() ) { QVector<quint16> & strip = istrip.next(); for ( int s = 0; s < strip.size(); s++ ) { if ( map.contains( strip[s] ) ) strip[s] = map[ strip[s] ]; } } // write back the data nif->setArray<Triangle>( iData, "Triangles", tris ); for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) nif->setArray<quint16>( iPoints.child( r, 0 ), strips[r] ); nif->set<int>( iData, "Num Vertices", verts.count() ); nif->updateArray( iData, "Vertices" ); nif->setArray<Vector3>( iData, "Vertices", verts ); nif->updateArray( iData, "Normals" ); nif->setArray<Vector3>( iData, "Normals", norms ); nif->updateArray( iData, "Vertex Colors" ); nif->setArray<Color4>( iData, "Vertex Colors", colors ); for ( int r = 0; r < nif->rowCount( iUVSets ); r++ ) { nif->updateArray( iUVSets.child( r, 0 ) ); nif->setArray<Vector2>( iUVSets.child( r, 0 ), texco[r] ); } // process NiSkinData QModelIndex iSkinInst = nif->getBlock( nif->getLink( iShape, "Skin Instance" ), "NiSkinInstance" ); QModelIndex iSkinData = nif->getBlock( nif->getLink( iSkinInst, "Data" ), "NiSkinData" ); QModelIndex iBones = nif->getIndex( iSkinData, "Bone List" ); for ( int b = 0; b < nif->rowCount( iBones ); b++ ) { QVector< QPair<int,float> > weights; QModelIndex iWeights = nif->getIndex( iBones.child( b, 0 ), "Vertex Weights" ); for ( int w = 0; w < nif->rowCount( iWeights ); w++ ) { weights.append( QPair<int,float>( nif->get<int>( iWeights.child( w, 0 ), "Index" ), nif->get<float>( iWeights.child( w, 0 ), "Weight" ) ) ); } for ( int x = weights.count() - 1; x >= 0; x-- ) { if ( ! used.contains( weights[x].first ) ) weights.remove( x ); } QMutableVectorIterator< QPair< int, float > > it( weights ); while ( it.hasNext() ) { QPair<int,float> & w = it.next(); if ( map.contains( w.first ) ) w.first = map[ w.first ]; } nif->set<int>( iBones.child( b, 0 ), "Num Vertices", weights.count() ); nif->updateArray( iWeights ); for ( int w = 0; w < weights.count(); w++ ) { nif->set<int>( iWeights.child( w, 0 ), "Index", weights[w].first ); nif->set<float>( iWeights.child( w, 0 ), "Weight", weights[w].second ); } } // process NiSkinPartition QModelIndex iSkinPart = nif->getBlock( nif->getLink( iSkinInst, "Skin Partition" ), "NiSkinPartition" ); if ( ! iSkinPart.isValid() ) iSkinPart = nif->getBlock( nif->getLink( iSkinData, "Skin Partition" ), "NiSkinPartition" ); if ( iSkinPart.isValid() ) { nif->removeNiBlock( nif->getBlockNumber( iSkinPart ) ); qWarning() << "the skin partition was removed, please add it again with the skin partition spell"; } } catch ( QString e ) { qWarning() << e.toAscii().data(); } }