void draw_triangle_optimized(float x0, float y0, float x1, float y1, float x2, float y2, byte r, byte g, byte blue) { float xmin = floor(lowest(x0, x1, x2)); float ymin = floor(lowest(y0, y1, y2)); float xmax = floor(highest(x0, x1, x2)); float ymax = floor(highest(y0, y1, y2)); float fa = fij(x0, y0, x1, y1, x2, y2); float fb = fij(x1, y1, x2, y2, x0, y0); float fc = fij(x2, y2, x0, y0, x1, y1); float fa_outside = fij(-1, -1, x1, y1, x2, y2) * fa > 0; float fb_outside = fij(-1, -1, x2, y2, x0, y0) * fb > 0; float fc_outside = fij(-1, -1, x0, y0, x1, y1) * fc > 0; for (float y = ymin; y <= ymax; y++) { for (float x = xmin; x <= xmax; x++) { float a = fij(x, y, x1, y1, x2, y2) / fa; float b = fij(x, y, x2, y2, x0, y0) / fb; float c = fij(x, y, x0, y0, x1, y1) / fc; if (a >= 0 && b >= 0 && c >= 0 && (a > 0 || fa_outside) && (b > 0 || fb_outside) && (c > 0 || fc_outside)) { PutPixel(x, y, r, g, blue); } } } }
int main() { int score[10] = { 67,98,75,63,82,79,81,91,66,84 }; sum(score); highest(score); lowest(score); average(score); printf("总分:%d\n", sum(score)); printf("最高分:%d\n", highest(score)); printf("最低分:%d\n", lowest(score)); printf("平均分:%.1f\n", average(score)); descending(score); getchar(); return 0; }
BVTerm BVTerm::substitute(const std::map<BVVariable,BVTerm>& _substitutions) const { BVTermType type = this->type(); if(type == BVTermType::CONSTANT) { return *this; } if(type == BVTermType::VARIABLE) { auto iter = _substitutions.find(variable()); if(iter != _substitutions.end()) { return iter->second; } return *this; } if(typeIsUnary(type)) { BVTerm operandSubstituted = operand().substitute(_substitutions); return BVTerm(type, operandSubstituted, index()); } if(typeIsBinary(type)) { BVTerm firstSubstituted = first().substitute(_substitutions); BVTerm secondSubstituted = second().substitute(_substitutions); return BVTerm(type, firstSubstituted, secondSubstituted); } if(type == BVTermType::EXTRACT) { BVTerm operandSubstituted = operand().substitute(_substitutions); return BVTerm(type, operandSubstituted, highest(), lowest()); } assert(false); return BVTerm(); }
void Histogram<T>::print () const { std::cout << "Total: " << size() << ", " << "Min: " << _min << ", " << "Max: " << _max << '\n'; std::cout << std::left << std::setw(6) << "-1" << '(' << std::setw(5) << lowest() << "-) " << std::right << std::setw(6) << underflow() << '\n'; for (unsigned i=0; i<_bins; ++i) { std::cout << std::left << std::setw(6) << i << '(' << std::setw(5) << low(i) << ", " << std::setw(5) << high(i) << ")" << std::right << std::setw(6) << _bin[i] << '\n'; } std::cout << std::left << std::setw(6) << _bins << '(' << std::setw(5) << highest() << "+) " << std::right << std::setw(6) << overflow() << '\n'; }
Vec3 Dude::getLowestLimbPosition() const { assert(0); // Need to fix this Vec3 lowest(0,100000,0); for( int i = 0; i < animSys.getNumBones(); i++ ) { const Vec3 &p = animSys.getBone(i)->getEndPos(); if(p.y < lowest.y) lowest = p; } return lowest; }
int Scm_BitsLowest0(const ScmBits *bits, int start, int end) { int sw = start/SCM_WORD_BITS; int sb = start%SCM_WORD_BITS; int ew = (end-1)/SCM_WORD_BITS; int eb = end%SCM_WORD_BITS; if (start == end) return -1; if (ew == sw) { u_long w = ~bits[sw] & SCM_BITS_MASK(sb, eb); if (w) return lowest(w) + sw*SCM_WORD_BITS; else return -1; } else { u_long w = ~bits[sw] & SCM_BITS_MASK(sb, 0); if (w) return lowest(w) + sw*SCM_WORD_BITS; for (;sw < ew; sw++) { if (~bits[sw]) return lowest(~bits[sw])+sw*SCM_WORD_BITS; } w = ~bits[ew] & SCM_BITS_MASK(0, eb); if (w) return lowest(w) + ew*SCM_WORD_BITS; return -1; } }
Tclef Tlevel::fixClef(quint16 cl) { if (cl == 0) // For backward compatibility - 'no clef' never occurs return Tclef(Tclef::e_treble_G_8down); // and versions before 0.8.90 kept here 0 if (cl == 1) { Tnote lowest(6, -2, 0); if (canBeGuitar() || loNote.chromatic() < lowest.chromatic() ) return Tclef(Tclef::e_treble_G_8down); // surely: 1 = e_treble_G was not intended here else return Tclef(Tclef::e_treble_G); } if (cl != 2 && cl != 4 && cl != 8 && cl != 16 && cl != 32 && cl != 64 && cl != 128) { qDebug() << "Fixed clef type. Previous value was:" << cl; return Tclef(Tclef::e_treble_G_8down); // some previous mess - when levels didn't' support clefs } return Tclef((Tclef::Etype)cl); }
int main(void) { int ans, i, j, x = 1, y = 1; for(i = 10; i < MAX; i++) { for(j = 10; j < i; j++) { if(check(i, j) == 1) { y *= i; x *= j; } } } ans = lowest(x, y); printf("answer: %d\n", ans); return 0; }
static constexpr range full() { return range(lowest(), highest()); }
void lowess(const std::vector<double> &x, const std::vector<double> &y, double f, long nsteps, double delta, std::vector<double> &ys, std::vector<double> &rw, std::vector<double>&res){ //{{{ long n=static_cast<long>(x.size()); bool ok=false; long nleft,nright, i, j, iter, last, m1, m2, ns; double cut, cmad, r, d1, d2, c1, c9, alpha, denom; if((n==0)||(static_cast<long>(y.size())!=n)) return; ys.resize(n); rw.resize(n); res.resize(n); if(n==1){ ys[0]=y[0]; return; } // ns - at least 2, at most n ns = std::max(std::min(static_cast<long>((f*n)),n),static_cast<long>(2)); for(iter=0;iter<nsteps+1; iter++){ // robustnes iterations nleft = 0; nright = ns-1; // index of last estimated point last = -1; // index of current point i=0; do{ while(nright<n-1){ // move <nleft,nright> right, while radius decreases d1 = x[i]-x[nleft]; d2 = x[nright+1] - x[i]; if(d1<=d2)break; nleft++; nright++; } // fit value at x[i] lowest(x,y,x[i],ys[i],nleft,nright,res,iter>0,rw,ok); if(!ok) ys[i]=y[i]; if(last<i-1){ // interpolate skipped points if(last<0){ } denom = x[i] - x[last]; for(j=last+1;j<i;j++){ alpha = (x[j]-x[last])/denom; ys[j] = alpha * ys[i] + (1.0-alpha)*ys[last]; } } last = i; cut = x[last]+delta; for(i=last+1;i<n;i++){ if(x[i]>cut)break; if(x[i]==x[last]){ ys[i]=ys[last]; last=i; } } i=std::max(last+1,i-1); }while(last<n-1); for(i=0;i<n;i++) res[i] = y[i]-ys[i]; if(iter==nsteps)break ; for(i=0;i<n;i++) rw[i]=abs(res[i]); sort(rw.begin(),rw.end()); m1 = n/2+1; m2 = n-m1; m1 --; cmad = 3.0 *(rw[m1]+rw[m2]); c9 = .999*cmad; c1 = .001*cmad; for(i=0;i<n;i++){ r = abs(res[i]); if(r<=c1) rw[i]=1; else if(r>c9) rw[i]=0; else rw[i] = (1.0-(r/cmad)*(r/cmad))*(1.0-(r/cmad)*(r/cmad)); } } }//}}}
void clear() { score = lowest(); deps.clear(); }
bool valid() const { return score > lowest(); }
Hypothesis() : score(lowest()), deps() {}
/// Reset to Zero (Empty). void zero() { this->first = lowest(); this->second = lowest(); }
void test() { // // Note really a test just yet, but we can at least print out all the values: // std::cout << "numeric_limits values for type " << typeid(Number).name() << std::endl; PRINT(is_specialized); if(std::numeric_limits<Number>::is_integer) { std::cout << std::hex << std::showbase; } std::cout << "max()" << " = " << (std::numeric_limits<Number>::max)() << std::endl; if(std::numeric_limits<Number>::is_integer) { std::cout << std::dec; } std::cout << "max()" << " = " << (std::numeric_limits<Number>::max)() << std::endl; std::cout << "min()" << " = " << (std::numeric_limits<Number>::min)() << std::endl; #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS PRINT(lowest()); #endif PRINT(digits); PRINT(digits10); #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS PRINT(max_digits10); #endif PRINT(is_signed); PRINT(is_integer); PRINT(is_exact); PRINT(radix); PRINT(epsilon()); PRINT(round_error()); PRINT(min_exponent); PRINT(min_exponent10); PRINT(max_exponent); PRINT(max_exponent10); PRINT(has_infinity); PRINT(has_quiet_NaN); PRINT(has_signaling_NaN); PRINT(has_denorm); PRINT(has_denorm_loss); PRINT(infinity()); PRINT(quiet_NaN()); PRINT(signaling_NaN()); PRINT(denorm_min()); PRINT(is_iec559); PRINT(is_bounded); PRINT(is_modulo); PRINT(traps); PRINT(tinyness_before); PRINT(round_style); typedef typename boost::mpl::if_c< std::numeric_limits<Number>::is_specialized, typename boost::multiprecision::number_category<Number>::type, boost::mpl::int_<500> // not a number type >::type fp_test_type; test_specific<Number>(fp_test_type()); }
static void clowess(double *x, double *y, int n, double f, int nsteps, double delta, double *ys, double *rw, double *res) { int i, iter, j, last, m1, m2, nleft, nright, ns; int ok; double alpha, c1, c9, cmad, cut, d1, d2, denom, r, sc; if (n < 2) { ys[0] = y[0]; return; } /* nleft, nright, last, etc. must all be shifted to get rid of these: */ x--; y--; ys--; /* at least two, at most n points */ ns = imax2(2, imin2(n, (int)(f*n + 1e-7))); /* robustness iterations */ iter = 1; while (iter <= nsteps+1) { nleft = 1; nright = ns; last = 0; /* index of prev estimated point */ i = 1; /* index of current point */ for(;;) { if (nright < n) { /* move nleft, nright to right */ /* if radius decreases */ d1 = x[i] - x[nleft]; d2 = x[nright+1] - x[i]; /* if d1 <= d2 with */ /* x[nright+1] == x[nright], */ /* lowest fixes */ if (d1 > d2) { /* radius will not */ /* decrease by */ /* move right */ nleft++; nright++; continue; } } /* fitted value at x[i] */ lowest(&x[1], &y[1], n, &x[i], &ys[i], nleft, nright, res, iter>1, rw, &ok); if (!ok) ys[i] = y[i]; /* all weights zero */ /* copy over value (all rw==0) */ if (last < i-1) { denom = x[i]-x[last]; /* skipped points -- interpolate */ /* non-zero - proof? */ for(j = last+1; j < i; j++) { alpha = (x[j]-x[last])/denom; ys[j] = alpha*ys[i] + (1.-alpha)*ys[last]; } } /* last point actually estimated */ last = i; /* x coord of close points */ cut = x[last]+delta; for (i = last+1; i <= n; i++) { if (x[i] > cut) break; if (x[i] == x[last]) { ys[i] = ys[last]; last = i; } } i = imax2(last+1, i-1); if (last >= n) break; } /* residuals */ for(i = 0; i < n; i++) res[i] = y[i+1] - ys[i+1]; /* overall scale estimate */ sc = 0.; for(i = 0; i < n; i++) sc += fabs(res[i]); sc /= n; /* compute robustness weights */ /* except last time */ if (iter > nsteps) break; /* Note: The following code, biweight_{6 MAD|Ri|} is also used in stl(), loess and several other places. --> should provide API here (MM) */ for(i = 0 ; i < n ; i++) rw[i] = fabs(res[i]); /* Compute cmad := 6 * median(rw[], n) ---- */ /* FIXME: We need C API in R for Median ! */ m1 = n/2; /* partial sort, for m1 & m2 */ rPsort((double *)rw, (int)n, (int)m1); if(n % 2 == 0) { m2 = n-m1-1; rPsort((double *)rw, (int)n, (int)m2); cmad = 3.*(rw[m1]+rw[m2]); } else { /* n odd */ cmad = 6.*rw[m1]; } if(cmad < 1e-7 * sc) /* effectively zero */ break; c9 = 0.999*cmad; c1 = 0.001*cmad; for(i = 0 ; i < n ; i++) { r = fabs(res[i]); if (r <= c1) rw[i] = 1.; else if (r <= c9) rw[i] = fsquare(1.-fsquare(r/cmad)); else rw[i] = 0.; } iter++; } }
int main(void){ int a; scanf("%d",&a); printf("%d\n",lowest(a)); return 0; }
/// Check if \em defined. bool defined() const { return (low() != highest() and high() != lowest()); }
/// Undefine Prior to sucessive calls to \c include. range& undefine() { low() = highest(); high() = lowest(); return *this; }
bool is_zero() const { return low() == lowest() and high() == lowest(); }
/// Reset to Zero (Empty). void clear() { this->first = highest(); this->second = lowest(); }
/// Return \em Full Range. static constexpr range none() { return range(lowest(), lowest()); }
/* * FowlerLittle * * http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u39.html#SEC39.1.1 * */ void FowlerLittle(const DEMGeo& orig, DEMGeo& deriv) { DEMGeo passes(orig.mWidth, orig.mHeight); DEMGeo lowest(orig.mWidth, orig.mHeight); DEMGeo highest(orig.mWidth, orig.mHeight); passes = NO_DATA; int x, y; for (y = 1; y < (orig.mHeight-1); ++y) for (x = 1; x < (orig.mWidth-1); ++x) { float e = orig.get(x,y); bool dif[8]; dif[0] = orig.get(x ,y+1) > e; dif[1] = orig.get(x+1,y+1) > e; dif[2] = orig.get(x+1,y ) > e; dif[3] = orig.get(x+1,y-1) > e; dif[4] = orig.get(x ,y-1) > e; dif[5] = orig.get(x-1,y-1) > e; dif[6] = orig.get(x-1,y ) > e; dif[7] = orig.get(x-1,y+1) > e; int cycles = 0; for (int n = 0; n < 8; ++n) if (dif[n] != dif[(n+7)%8]) ++cycles; if (cycles == 0) deriv(x,y) = orig(x,y); if (cycles > 2) passes(x,y) = 1.0; } for (y = 1; y < (orig.mHeight); ++y) for (x = 1; x < (orig.mWidth); ++x) { float e[4]; e[0] = orig.get(x-1,y-1); e[1] = orig.get(x ,y-1); e[2] = orig.get(x-1,y ); e[3] = orig.get(x ,y ); if (e[0] < e[1] && e[0] < e[2] && e[0] < e[3]) lowest(x-1,y-1) = 1; if (e[0] > e[1] && e[0] > e[2] && e[0] > e[3]) highest(x-1,y-1) = 1; if (e[1] < e[0] && e[1] < e[2] && e[1] < e[3]) lowest(x ,y-1) = 1; if (e[1] > e[0] && e[1] > e[2] && e[1] > e[3]) highest(x ,y-1) = 1; if (e[2] < e[0] && e[2] < e[1] && e[2] < e[3]) lowest(x-1,y ) = 1; if (e[2] > e[0] && e[2] > e[1] && e[2] > e[3]) highest(x-1,y ) = 1; if (e[3] < e[0] && e[3] < e[1] && e[3] < e[2]) lowest(x ,y ) = 1; if (e[3] > e[0] && e[3] > e[1] && e[3] > e[2]) highest(x ,y ) = 1; } for (y = 0; y < (orig.mHeight); ++y) for (x = 0; x < (orig.mWidth); ++x) { if (passes(x,y) != 0.0) if (lowest(x,y) == 0.0 || highest(x,y) == 0.0) deriv(x,y) = orig(x,y); } }
void LayeredConfiguration::addFront(AbstractConfiguration* pConfig, bool shared) { add(pConfig, lowest(), false, shared); }
int lowess(const ContainerType& x, const ContainerType& y, double frac, // parameter f int nsteps, ValueType delta, ContainerType& ys, ContainerType& resid_weights, // vector rw ContainerType& weights // vector res ) { bool fit_ok; size_t ns, n(x.size()); if (n < 2) { ys[0] = y[0]; return 1; } // how many points around estimation point should be used for regression: // at least two, at most n points size_t tmp = (size_t)(frac * (double)n); ns = std::max(std::min(tmp, n), (size_t)2); // robustness iterations for (int iter = 1; iter <= nsteps + 1; iter++) { // start of array in C++ at 0 / in FORTRAN at 1 // last: index of prev estimated point // i: index of current point size_t i(0), last(-1), nleft(0), nright(ns -1); // Fit all data points y[i] until the end of the array do { // Identify the neighborhood around the current x[i] // -> get the nearest ns points update_neighborhood(x, n, i, nleft, nright); // Calculate weights and apply fit (original lowest function) fit_ok = lowest(x, y, n, x[i], ys[i], nleft, nright, weights, (iter > 1), resid_weights); // if something went wrong during the fit, use y[i] as the // fitted value at x[i] if (!fit_ok) ys[i] = y[i]; // If we skipped some points (because of how delta was set), go back // and fit them by linear interpolation. if (last < i - 1) { interpolate_skipped_fits(x, i, last, ys); } // Update the last fit counter to indicate we've now fit this point. // Find the next i for which we'll run a regression. update_indices(x, n, delta, i, last, ys); } while (last < n - 1); // compute current residuals for (i = 0; i < n; i++) { weights[i] = y[i] - ys[i]; } // compute robustness weights except last time if (iter > nsteps) break; calculate_residual_weights(n, weights, resid_weights); } return 0; }
/// Create Default as Undefined Range. range() : range(highest(), lowest()) {}
void LayeredConfiguration::addFront(AbstractConfiguration* pConfig) { add(pConfig, lowest(), false, true); }
/* * create an octree, load the heightmap, load all * map quads into object structures and place them * in the appropriate leaf nodes of the octree */ struct map * load_map(const char *filename) { unsigned int i, j, k; unsigned char *data; unsigned int width, height; int type; unsigned int tilesize = 8; float xydiv = 1.0f; float zdiv = 9.0f; static struct map map_structure; struct vertex vertices[4]; struct object *o; struct plane_object *p; struct octree_node *on; /* data is a pointer to the raw rgb data of the heightmap */ data = (unsigned char *)read_png(filename, &width, &height, &type); if(!data) { fprintf(stderr, "Error: Couldn't load heightmap %s\n", filename); return NULL; } map_structure.octree = new_octree_branch(NULL, -((float)width / xydiv), (float)width / xydiv, -((float)height / xydiv), (float)height / xydiv, -255.0f, 255.0f); if(!map_structure.octree) { fprintf(stderr, "Error: Couldn't create octree\n"); free(data); return NULL; } snprintf(map_structure.skypic, 256, "data/sky.png"); /* * create map quads from heightmap; the z value of each * point is taken from the pixel corresponding to the * current position on the heightmap using the get_pixel * function */ k = 0; for(i = 0; i < height - tilesize; i+= tilesize) { for(j = 0; j < width - tilesize; j += tilesize) { vertices[k].texcoord[0] = 0.25f * (j/tilesize % 4); vertices[k].texcoord[1] = 0.25f * (i/tilesize % 4); vertices[k].point[0] = (float)j / xydiv - (float)(width / 2) / xydiv; vertices[k].point[1] = (float)(i + tilesize) / xydiv - (float)(height / 2) / xydiv; vertices[k].point[2] = (float)get_pixel(data, j, i + tilesize, width) / zdiv; k++; vertices[k].texcoord[0] = 0.25f * ((j/tilesize % 4) + 1.0f); vertices[k].texcoord[1] = 0.25f * (i/tilesize % 4); vertices[k].point[0] = (float)(j + tilesize) / xydiv - (float)(width / 2) / xydiv; vertices[k].point[1] = (float)(i + tilesize) / xydiv - (float)(height / 2) / xydiv; vertices[k].point[2] = (float)get_pixel(data, j + tilesize, i + tilesize, width) / zdiv; k++; vertices[k].texcoord[0] = 0.25f * ((j/tilesize % 4) + 1.0f); vertices[k].texcoord[1] = 0.25f * ((i/tilesize % 4) + 1.0f); vertices[k].point[0] = (float)(j + tilesize) / xydiv - (float)(width / 2) / xydiv; vertices[k].point[1] = (float)i / xydiv - (float)(height / 2) / xydiv; vertices[k].point[2] = (float)get_pixel(data, j + tilesize, i, width) / zdiv; k++; vertices[k].texcoord[0] = 0.25f * (j/tilesize % 4); vertices[k].texcoord[1] = 0.25f * ((i/tilesize % 4) + 1.0f); vertices[k].point[0] = (float)j / xydiv - (float)(width / 2) / xydiv; vertices[k].point[1] = (float)i / xydiv - (float)(height / 2) / xydiv; vertices[k].point[2] = (float)get_pixel(data, j, i, width) / zdiv; k = 0; o = create_object(OBJ_PLANE); if(!o) { free(data); free_octree_branch(map_structure.octree); return NULL; } o->render_separately = 0; o->vertices = malloc(sizeof(struct vertex) * 4); if(!o->vertices) { fprintf(stderr, "Error: Couldn't allocate memory for heightmap vertices\n"); free(data); free_octree_branch(map_structure.octree); return NULL; } o->num_vertices = 4; memcpy(o->vertices, vertices, sizeof(struct vertex) * 4); p = (struct plane_object *)(o->aux); setup_plane(p->plane, o->vertices[0].point, o->vertices[1].point, o->vertices[2].point); p->minx = lowest(o->vertices[0].point[0], o->vertices[1].point[0], o->vertices[2].point[0], o->vertices[3].point[0]); p->maxx = highest(o->vertices[0].point[0], o->vertices[1].point[0], o->vertices[2].point[0], o->vertices[3].point[0]); p->miny = lowest(o->vertices[0].point[1], o->vertices[1].point[1], o->vertices[2].point[1], o->vertices[3].point[1]); p->maxy = highest(o->vertices[0].point[1], o->vertices[1].point[1], o->vertices[2].point[1], o->vertices[3].point[1]); p->minz = lowest(o->vertices[0].point[2], o->vertices[1].point[2], o->vertices[2].point[2], o->vertices[3].point[2]); p->maxz = highest(o->vertices[0].point[2], o->vertices[1].point[2], o->vertices[2].point[2], o->vertices[3].point[2]); on = get_octree_leaf_from_point(map_structure.octree, o->vertices[0].point); add_object_to_octree_node(on, o); } } free(data); fprintf(stderr, "%s loaded\n", filename); return &map_structure; }