bool BoundingPolygon::collides(const BoundingPolygon& comp) { for(int i = 0; i < nrOfEdges; i++) { float min = findMin(normals[i]); float compMax = comp.findMax(normals[i]); if(min > compMax) { return false; } float max = findMax(normals[i]); float compMin = comp.findMin(normals[i]); if(max < compMin) { return false; } } for(int i = 0; i < comp.nrOfEdges; i++) { float min = findMin(comp.normals[i]); float compMax = comp.findMax(comp.normals[i]); if(min > compMax) { return false; } float max = findMax(comp.normals[i]); float compMin = comp.findMin(comp.normals[i]); if(max < compMin) { return false; } } return true; }
int main() { int n,i,j; scanf("%d%d", &n, &k); hashInit(); scanf("%d", A+1); amax=(amin=A[1]); for(i=2; i<=n; i++) { scanf("%d", A+i); if(A[i]>amax) amax=A[i]; if(A[i]<amin) amin=A[i]; } for(j=1; j<k; j++) hashInsert(A[j]); for(i=1; j<n; i++, j++) { hashInsert(A[j]); A[i-1]=findMax(); printf("%d ",findMin()); hashDelete(A[i]); } hashInsert(A[j]); A[i-1]=findMax(); printf("%d\n",findMin()); for(i=0; i<n-k; i++) printf("%d ",A[i]); printf("%d\n",A[i]); scanf("%d", A); return 0; }
bool isValidBST(TreeNode *root) { if (root == NULL) return true; if (isValidBST(root->left) && isValidBST(root->right)) { if (root->left && root->right) { int max = findMax(root->left); int min = findMin(root->right); if (max < root->val && root->val < min) return true; return false; } else if (root->left && !root->right) { int max = findMax(root->left); if (root->val > max) return true; return false; } else if (!root->left && root->right) { int min = findMin(root->right); if (root->val < min) return true; return false; } else return true; } return false; }
int main(int argc, char const *argv[]) { FILE *finp, *foutp; int mark1 = 0, mark2 = 0, num1[40] = {0}, num2[40] = {0}, max1, max2; char str1[20], str2[20] ; int decimalism1[36] = {-1}, decimalism2[36] = {-1}; int result, index[2]; finp = fopen(PATH_IN, "r"); foutp = fopen(PATH_OUT, "w"); while(!feof(finp)) { fscanf(finp, "%s", str1); if (str1[0] != '0') { fscanf(finp, "%s", str2); }else { continue; } mark1 = toNum(str1, num1); mark2 = toNum(str2, num2); if((mark1 == 1) && (mark2 == 1)) { max1 = findMax(num1, (int)strlen(str1)); max2 = findMax(num2, (int)strlen(str2)); convertTodecimalism(num1, decimalism1, max1, (int)strlen(str1)); convertTodecimalism(num2, decimalism2, max2, (int)strlen(str2)); result = compare(decimalism1, max1, decimalism2, max2, index); if(result == 0) { fprintf(foutp, "%s is not equal to %s in any base 2..36\n", str1, str2); }else { fprintf(foutp, "%s(base%d) = %s(base%d)\n", str1, index[0], str2, index[1]); } }else { if(mark1 == 0) { fprintf(foutp, "%s is illegal number expression\n", str1); } if(mark2 == 0) { fprintf(foutp, "%s is illegal number expression\n", str2); } } } fclose(finp); fclose(foutp); }
void processSummarize() { Customer* max_bottles = findMax ("Bottles"); Customer* max_diapers = findMax ("Diapers"); Customer* max_rattles = findMax ("Rattles"); printf ("There are %d Bottles, %d Diapers and %d Rattles in inventory\n", num_bottles, num_diapers, num_rattles); printf ("we have had a total of %d different customers\n", database.size ()); if (!max_bottles) { //null pointer printf ("no one has purchased any Bottles\n"); } else { //don't know if allowed to do max_bottles->something printf ("%s has purchased the most Bottles (%d)\n", max_bottles->name.c_str (), max_bottles->bottles); } if (!max_diapers) { printf ("no one has purchased any Diapers\n"); } else { printf ("%s has purchased the most Diapers (%d)\n", max_diapers->name.c_str (), max_diapers->diapers); } if (!max_rattles) { printf ("no one has purchased any Rattles\n"); } else { printf ("%s has purchased the most Rattles (%d)\n", max_rattles->name.c_str (), max_rattles->rattles); } }
/* void StatsFrame::addTick(int64_t bdiff, uint64_t tdiff, StatList& lst, AvgList& avg, int scroll) { int64_t bspeed = calcSpeed(bdiff, tdiff); avg.push_front(bspeed); bspeed = 0; for (auto ai = avg.cbegin(); ai != avg.cend(); ++ai) { bspeed += *ai; } bspeed /= avg.size(); updateStatList(bspeed, lst, scroll); while (avg.size() > SPEED_APPROXIMATION_INTERVAL_S) { avg.pop_back(); } } */ LRESULT StatsFrame::onTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { const uint64_t tick = MainFrame::getLastUpdateTick(); const uint64_t tdiff = tick - lastTick; if (tdiff == 0) return 0; const uint64_t scrollms = (tdiff + scrollTick) * PIX_PER_SEC; const uint64_t scroll = scrollms / 1000; if (scroll == 0) return 0; scrollTick = scrollms - (scroll * 1000); CRect rc; GetClientRect(rc); rc.left = twidth; ScrollWindow(-((int)scroll), 0, rc, rc); const int64_t d = MainFrame::getLastDownloadSpeed(); //const int64_t ddiff = d - m_lastSocketsDown; const int64_t u = MainFrame::getLastUploadSpeed(); //const int64_t udiff = u - m_lastSocketsUp; const int64_t dt = DownloadManager::getRunningAverage(); const int64_t ut = UploadManager::getRunningAverage(); // [~]IRainman //addTick(ddiff, tdiff, m_DownSockets, m_DownSocketsAvg, (int)scroll); //addTick(udiff, tdiff, m_UpSockets, m_UpSocketsAvg, (int)scroll); addAproximatedSpeedTick(d, m_DownSockets, (int)scroll); addAproximatedSpeedTick(u, m_UpSockets, (int)scroll); addAproximatedSpeedTick(dt, m_Downloads, (int)scroll); addAproximatedSpeedTick(ut, m_Uploads, (int)scroll); StatIter i; int64_t mspeed = 0; findMax(m_DownSockets, i, mspeed); findMax(m_UpSockets, i, mspeed); // [+]IRainman findMax(m_Downloads, i, mspeed); findMax(m_Uploads, i, mspeed); // [~]IRainman if (mspeed > m_max || ((m_max * 3 / 4) > mspeed)) { m_max = mspeed + 1;// [!] IRainman fix: +1 Invalidate(); } lastTick = tick; //m_lastSocketsUp = u; //m_lastSocketsDown = d; doTimerTask(); return 0; }
int fillToTheRight(std::vector<int> &histogram, int leftIdx) { int maxIdx = leftIdx, rightMaxIdx = findMax(histogram, maxIdx + 1, histogram.size() - 1), volume = 0; while (maxIdx != histogram.size() - 1 && histogram[maxIdx] != 0) { volume += volumeBetween(histogram, maxIdx, rightMaxIdx); maxIdx = rightMaxIdx; rightMaxIdx = findMax(histogram, rightMaxIdx + 1, histogram.size() - 1); } return volume; }
int fillToTheLeft(std::vector<int> &histogram, int rightIdx) { int maxIdx = rightIdx, leftMaxIdx = findMax(histogram, 0, maxIdx - 1), volume = 0; while (maxIdx != 0 && histogram[maxIdx] != 0) { volume += volumeBetween(histogram, leftMaxIdx, maxIdx); maxIdx = leftMaxIdx; leftMaxIdx = findMax(histogram, 0, leftMaxIdx - 1); } return volume; }
void DobierzNastawy(fxpnt_matrix_t** Y, fxpnt_matrix_t** U, volatile PIDfloat_t *pid, int d, int SPS){ int delay = 10; int delay_ob = 0; float k, a, T0; int i; Skok(Y, U, 500, delay_ob, delay); int length = (*Y)->rows; /* obiekt z cz³onem ca³kuj¹cym */ if(fabs((*Y)->matrix[length-1][0] - (*Y)->matrix[(int)ceil(0.9*length)][0]) > 0.05*(*Y)->matrix[length-1][0]) { k = ((*Y)->matrix[(int)ceil(0.5*length)][0] - (*Y)->matrix[(int)ceil(0.5*length)-1][0])/(1.0/SPS); a = (*Y)->matrix[(int)ceil(0.5*length)][0] - k * (int)ceil(0.5*length)* 1.0/SPS; T0 = -a/k; } else { int y; fxpnt_matrix_t *K; K = initMatrix((*Y)->rows-1, 1); for(i = 0; i < (*Y)->rows - 1; i++) K->matrix[i][0] = (*Y)->matrix[i+1][0]-(*Y)->matrix[i][0]; y = findMax(K); m_free(&K); k = ((*Y)->matrix[y+1][0]-(*Y)->matrix[y][0])/SPS; a = (*Y)->matrix[y][0] - (float)(k*SPS*y); T0 = -a/k; } pid->_Kp = fabs(0.95/a); pid->_Ti = (2.4*abs(T0)); pid->_Td = (0.4*abs(T0)); }
int Solution::maximumGap(const vector<int> &A) { if(A.size()<2){ return 0; } if(A.size()==2){ return max(A[0],A[1])-min(A[0],A[1]); } int num_min=findMin(A); int num_max=findMax(A); int len=(num_max-num_min)/(A.size()-1)+1; vector<pair<int, int>> buckets (A.size(),pair<int,int>(INT_MAX, INT_MIN)); for(int i=0;i<A.size();i++){ int index=(A[i]-num_min)/len; buckets[index].first=min(buckets[index].first,A[i]); buckets[index].second=max(buckets[index].second,A[i]); } int gap=0; int prev=buckets[0].second; for(int i=1;i<buckets.size();i++) { if(prev!=INT_MIN && buckets[i].first!=INT_MAX){ gap=max(gap,buckets[i].first-prev); prev=buckets[i].second; } } return gap; }
/* pA: the pointer of the Matrix A|b rowMax,colMax:size of matirx pX: solution vector return value: -1 solving equation failed 1 resolve result successfully */ int gaussLesung(double *pA, int rowMax,int colMax, double *pX) { double *pMatrix = pA; int i; double product; product = 1; if((1+rowMax)!=colMax) return -1; for(i = 0; i < rowMax; i++) { int l; printf("%d,\n",i); l = findMax(pMatrix, rowMax, colMax, i,i); exchangeRow(pMatrix, rowMax, colMax, l, i); eliminate(pMatrix, rowMax, colMax, i, i); outputMatrix(pMatrix, rowMax, colMax); } for(i = 0; i < rowMax; i++)product = product * pMatrix[i*colMax+i]; if(product==0)return -1; solveX(pMatrix, rowMax,colMax, pX); return 1; }
int main() { Tree t; Node *root = t.root; cout << "Max value is " << findMax(root); }
int main( ) { vector<int> v1( 37 ); vector<double> v2( 40 ); vector<string> v3( 80 ); vector<IntCell> v4( 75 ); // Additional code to fill in the vectors not shown cout << findMax( v1 ) << endl; // OK: Comparable = int cout << findMax( v2 ) << endl; // OK: Comparable = double cout << findMax( v3 ) << endl; // OK: Comparable = string cout << findMax( v4 ) << endl; // Illegal; operator< undefined return 0; }
void main() { int input[MAX]; int i; int check; tree_type tree; makeNullTree(&tree); tree_type temp; printf("Type in the input: \n"); for (i = 0; i < MAX; ++i) { printf("%d-th number: ", i + 1); scanf("%d", &input[i]); insert(&tree, input[i]); } printf("Type in a value to delete: "); scanf("%d", &check); delete(&tree, check); reverseTree(&tree); printf("\nThe tree in preoder: \n"); preOrder(tree, display); printf("\nThe tree in inoder: \n"); inOrder(tree, display); printf("\nThe tree in postoder: \n"); postOrder(tree, display); printf("\n"); temp = findMin(tree); printf("The min element: %d\n", temp->info); temp = findMax(tree); printf("The max element: %d\n", temp->info); freeTree(tree); }
int computeMedian(int list1[],int start1, int end1, int list2[],int start2, int end2) { int s1,e1,s2,e2,m1,m2; s1=start1; s2=start2; e1=end1; e2=end2; if((e1-s1==1)&&(e2-s2==1)) { int medianSum = findMax(list1[0],list2[0])+findMin(list1[1],list2[1]); return medianSum/2; } m1 = FindMedianIndex(list1,s1,e1); m2= FindMedianIndex(list2,s2,e2); if(list1[m1]== list2[m2]) { return list1[m1]; } if(m1>m2) { return computeMedian(list1,s1,m1,list2,m2,e2); } else { return computeMedian(list1,m1,e1,list2,s1,m2); } }
ListItem extractMax() { int maxIndex = findMax(); ListItem max = m_list[maxIndex]; deleteIndex(maxIndex); return max; }
struct BstNode* findMax(struct BstNode* root){ if(root==NULL){ printf("Error!!");} else if(root->right==NULL){return root->data;} return findMax(root->right); };
// prints a graph comparing the sample values visually void printGraph(int samples[], int noOfSamples){ int max = findMax(samples, noOfSamples); cout << "Graph:" << endl; for (int i = 0; i < noOfSamples; i++){ printBar(samples[i], max); } }
/* * Packages a JSON containing max, min and average temperatures and returns it for sending. * Returns "No data available." when temperature array is empty of there has been a problem receiving data. * Returns "Arudino Error!!!" if the Arudino is currently in an error state (such as when it is disconnected after starting). */ char* packageAvgJSON(){ char* latest_temp = (char*) malloc(1000); if (latest_temp == NULL) { printf("\nAn error occurred while allocating memory for your request. Please try again.\n"); return NULL; } if (arduinoError){ sprintf(latest_temp, "{\n\"name\":\"Arudino Error!!!\"\n}\n"); } else { if (nextTempPointer == 0 ){ if (temps[3599] == -274.0){ sprintf(latest_temp, "{\n\"name\":\"No data available.\"\n}\n"); return latest_temp; } } else { if (temps[nextTempPointer - 1] == -274.0){ sprintf(latest_temp, "{\n\"name\":\"No data available.\"\n}\n"); return latest_temp; } } double max = findMax(); double min = findMin(); double average = findAverage(); printf("%f\n%f\n%f\n\n", max, min, average); if (cOrF == 'F') { max = max * 9 / 5 + 32; min = min * 9 / 5 + 32; average = average * 9 / 5 + 32; } sprintf(latest_temp, "{\n\"name\":\"H: %.1f L: %.1f AVG: %.1f\"\n}\n", max, min, average); } return latest_temp; }
void BST::remove(node *&root, Key k) { if (root == NULL) return; if (k < root->item.key) return remove(root->left, k); else if (k > root->item.key) return remove(root->right, k); else { if (root->left == NULL && root->right == NULL) { // leaf delete root; root = NULL; } else if (root->right == NULL) { // one-degree node node *tmp = root; root = root->left; delete tmp; else if (root->left == NULL) { // one-degree node node *tmp = root; root = root->right; delete tmp; } else { // two-degree node node *&replace = findMax(root->left); root->item = replace->item; node *tmp = replace; replace = replace->left; // the largest key must be in // a leaf node or one-degree node delete tmp; } return; }
void MAX7219::displayText(){ //printf("Start displayText()\n"); vector<MAX7219::Punkt> ausgabe = MAX7219::text; //printf("vector übergeben\n"); int displayIndex=0; int maxX = findMax(MAX7219::text); //printf("maxX: %d\n", maxX); //printf("Start while\n"); while(displayIndex-2 < maxX) { deleteAll(); MAX7219_buffer_out(); int zweiDimArray[8][8] = {0}; //printf("displayIndex: %d\n", displayIndex); //zweiDimArray[8][8] = { 0 }; for(int i = 0; i < ausgabe.size();i++){ if(ausgabe.at(i).x<displayIndex+8 && ausgabe.at(i).x>=displayIndex) { zweiDimArray[ausgabe.at(i).x - displayIndex][ausgabe.at(i).y] = 1; } } displayIndex++; //printf("Print Led\n"); displayZeichen(zweiDimArray); MAX7219_buffer_out(); // Output the buffer //usleep(200000); usleep(200000); } //printf("Ende displayText()\n"); }
void doWorker() { printf("[%s.%d] worker started\n", processor_name, my_rank); // begin parallel code; fill in the missing code here MPI_Status status; int master_id = 0; int i = 0; int n = 0; int start = 0; MPI_Recv(&n, 1, MPI_INT, master_id, 0, MPI_COMM_WORLD, &status); int *array = (int*) malloc(sizeof(int) * n); MPI_Recv(array, n, MPI_INT, master_id, 0, MPI_COMM_WORLD, &status); int size = 6; int *newArray = (int*) malloc(sizeof(int) * n); newArray[0] = calcSum(array, n); newArray[1] = calcMean(array, n); newArray[2] = findMax(array, n); newArray[3] = findMin(array, n); MPI_Send(&n, 1, MPI_INT, worker_id, 0, MPI_COMM_WORLD); MPI_Send(&array[start], n, MPI_INT, worker_id, 0, MPI_COMM_WORLD); // end parallel code; no more code change required printf("[%s.%d] worker completed\n", processor_name, my_rank); }
int ts_last(TreeSet *ts, void **element) { TNode *current = findMax(ts->root); if (current == NULL) return 0; *element = current->element; return 1; }
int main() { int offset; assume(offset % WORKPERTHREAD == 0 && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX); while(1) { __CPROVER_ASYNC_1: findMax(offset); } }
MinMaxOut findMinMax::findExtrema() const { MinMaxOut res; res.max = findMax(); CCIO::cout << "Maximum eigenvalue : " << res.max << "\n"; res.min = findMin(res.max); CCIO::cout << "Minimum eigenvalue : " << res.min << "\n"; return res; }
int radixSort(int a[], int size){ int m= findMax (a,size); int exp; for(exp = 1;m/exp>0;exp = exp*10){ countSort(a,size,exp); } }
void makeEmpty( ) { while( !isEmpty( ) ) { findMax( ); // Splay max item to root remove( root->element ); } }
NodePtr findMax(NodePtr& root) const { if (root == nullptr || root->right == nullptr) { return root; } return findMax(root->right); }
//need to modify deletemax and min - THESE DO NOT WORK!!! void Heap::deleteMax() { int max = findMax(0); swap(max, (size-1)); heap[size-1] = 0; size--; trickleDown(max); }
Solver::Solver (std::vector<double> coords, std::vector<int> total) : coords(coords), total(total) { findMax (); for (int i = 0; i < (int)coords.size(); i++) { steps.push_back(coords[i] / (double)total[i]); } results = new int[size -1]; diff = new double[size - 1]; }