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); } } } }
void main() { int a,b,c,d,e,f,g,h,i,m1,m2,m3,m; int highest(int,int,int); clrscr(); cout<<"Enter 9 integers="; cin>>a>>b>>c>>d>>e>>f>>g>>h>>i; m1=highest(a,b,c); m2=highest(d,e,f); m3=highest(g,h,i); m=highest(m1,m2,m3); cout<<"Highest="<<m<<'\n'; getch(); }
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; }
void main() /* 主函数 */ { int i, j, r, c; float h; r = 0; c = 1; input_stu(); /* 调用函数input_stu,输入学生各门功课的成绩 */ avr_stu(); /* 调用函数avr_stu,求出每个学生的平均分 */ avr_cor(); /* 调用函数avr_cor,找出学生成绩中的最高分*/ printf("\n 序号 课程1 课程2 课程3 课程4 课程5 平均分"); for(i=0; i<N; i++) { printf("\n NO%2d", i+1); for(j=0; j<M; j++) printf("%8.2f", score[i][j]); printf("%8.2f", a_stu[i]); } printf("\n课平均"); for(j=0; j<M; j++) printf("%8.2f", a_cor[j]); h = highest(&r, &c); printf("\n\n最高分%8.2f是 %d号学生的第%d门课\n", h, r, c); printf(" 方差 %8.2f\n", s_diff()); }
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(); }
int main() { int i,j; float h; input_stu(); aver_stu(); aver_cour(); printf("\n NO. cour1 cour2 cour3 cour4 cour5 aver \n"); for(i=0;i<N;i++) { printf("\n NO %2d",i+1); for(j=0;j<M;j++) printf("%8.2f",score[i][j]); printf("%8.2f\n",a_stu[i]); } printf("naverage:"); for (j=0;j<M;j++) printf("%8.2f",a_cour[j]); printf("\n"); h=highest(); printf("highest:%7.2f NO. %2d course %2d\n",h,r,c); printf("variance %8.2f\n",s_var()); return 0; }
int main(){ int i = 0, j = 0; float h = 0.0; int stu = 0, cor = 1; printf("请输入4个学生3门课程:\n"); input_stu(); average_stu(); average_course(); printf("序号 课程1 课程2 课程3 平均分\n"); for(i=1; i<=M; ++i){ printf("学号%d ", i); for(j=1; j<=N; ++j){ printf("%5.2f ", score[i][j]); } printf("%5.2f", a_stu[i]); printf("\n"); } for(j=1; j<=N; ++j){ printf("课程%d的平均分是:%5.2f\n", j, a_course[j]); } h = highest(&stu, &cor); printf("最高分%5.2f是学号%d的课程%d\n", h, stu, cor); printf("方差是%5.2f\n", average_diff());; return 0; }
int trap(vector<int>& height) { if (height.size() < 3) return 0; vector<int> cnt(height.size(), 0); vector<int> area(height.size(), 0); vector<int> highest(height.size(), 0); cnt[0] = height[0]; for (int i = 1, p, h; i < height.size(); ++i) { cnt[i] = cnt[i-1] + height[i]; p = highest[i-1], h = height[p]; if (height[i] >= h) { highest[i] = i; } else { highest[i] = p; p = i - 1, h = height[i]; for (; p >= 0 && height[p] < h; --p) /* empty */; } area[i] = (i - p - 1) * h - (cnt[i-1] - cnt[p]) + area[p]; if (area[i] < 0) area[i] = 0; } return area.back(); }
int main(void) { int i,j; float h; input_stu(); aver_stu(); aver_cour(); for(i=0;i<N;i++) { printf("第%d名学生的平均成绩为:%8.2f",a_stu[i]); } for(j=0;i<M;j++) { printf("第%d门课程的平均成绩为:%8.2f",a_cour[j]); } h=highest(); printf("最高分数是学生%d在课程%d中所取得的%8.2f分\n",r,c,h); printf("方差为%8.2f",s_var()); return 0; }
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'; }
void* calloc(size_t number, size_t size) { size_t number_size = 0; /* This prevents an integer overflow. A size_t is a typedef to an integer * large enough to index all of memory. If we cannot fit in a size_t, then * we need to fail. */ if (highest(number) + highest(size) > sizeof(size_t) * CHAR_BIT) { errno = ENOMEM; return NULL; } number_size = number * size; void* ret = malloc(number_size); if (ret) { memset(ret, 0, number_size); } return ret; }
int Scm_BitsHighest0(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 highest(w) + sw*SCM_WORD_BITS; else return -1; } else { u_long w = ~bits[ew] & SCM_BITS_MASK(0, eb); if (w) return highest(w) + ew*SCM_WORD_BITS; for (ew--;sw < ew; ew--) { if (~bits[ew]) return highest(~bits[ew])+ew*SCM_WORD_BITS; } w = ~bits[sw] & SCM_BITS_MASK(sb, 0); if (w) return highest(w) + sw*SCM_WORD_BITS; return -1; } }
main() { int num1,num2,num3; printf("Enter %d numbers\n",SIZE); scanf("\n%d%d%d",&num1,&num2,&num3); //call on the function highest() highest(num1,num2,num3); printf("Main() ended"); }//end main()
shared_ptr<ChunkModelResult> compute_chunk(const ChunkModelData &data, const BlockTypeInfo &block_data) { std::vector<BlockData> blocks(XZ_SIZE * XZ_SIZE * XZ_SIZE); std::vector<char> highest(XZ_SIZE * XZ_SIZE); BlockData *above = data.above->blocks; BlockData *below = data.below->blocks; BlockData *left = data.left->blocks; BlockData *right = data.right->blocks; BlockData *front = data.front->blocks; BlockData *back = data.back->blocks; BlockData *above_left = data.above_left->blocks; BlockData *above_right = data.above_right->blocks; BlockData *above_front = data.above_front->blocks; BlockData *above_back = data.above_back->blocks; BlockData *above_left_front = data.above_left_front->blocks; BlockData *above_right_front = data.above_right_front->blocks; BlockData *above_left_back = data.above_left_back->blocks; BlockData *above_right_back = data.above_right_back->blocks; BlockData *left_front = data.left_front->blocks; BlockData *right_front = data.right_front->blocks; BlockData *left_back = data.left_back->blocks; BlockData *right_back = data.right_back->blocks; const char *is_transparent = block_data.is_transparent; const char *is_plant = block_data.is_plant; const char *state = block_data.state; int ox = - CHUNK_SIZE - 1; int oy = - CHUNK_SIZE - 1; int oz = - CHUNK_SIZE - 1; /* Populate the blocks array with the chunk itself */ const BlockData *self = data.self->blocks; CHUNK_FOR_EACH(self, ex, ey, ez, eb) { int x = ex - ox; int y = ey - oy; int z = ez - oz; blocks[XYZ(x, y, z)] = eb; if (!is_transparent[eb.type]) { highest[XZ(x, z)] = std::max((int)highest[XZ(x, z)], y); } } END_CHUNK_FOR_EACH;
int main(){ int i,j; float a[M][N]; float ave_stu(float score[M][N],int n),ave_sub(float score[M][N],int n),variance(float score[M][N]); void highest(float score[M][N]); for(i=0;i<10;i++){ printf("Please input the scores of student NO.%d\n",i+1); for(j=0;j<5;j++) scanf("%f",&a[i][j]); } for(i=0;i<M;i++) printf("The average score of student NO.%d is %4.1f.\n",i+1,ave_stu(a,i)); for(j=0;j<N;j++) printf("The average score of subject NO.%d is %4.1f.\n",j+1,ave_sub(a,j)); highest(a); printf("The highest score %4.1f is subject NO.%d of student NO.%d.\n",highest_score,highest_sub+1,highest_stu+1); printf("The variance of the average scores is %f.\n",variance(a)); return 0; }
main() { int i; int input[NUMBERS]; int ans; for (i=0;i<NUMBERS;i++) { printf ("Please enter element %d.\n", i); scanf ("%d", &input[i]); }//end for ans=highest(input); printf ("\nThe highest is %d.", ans); flushall(); getchar(); }//end main()
int main() { printf("对每个学生的成绩按照语文数学英语物理生物的顺序输入"); int i,j; float h; float ave1,ave2,ave3,ave4,ave5,ave6,ave7,ave8,ave9,ave10; float a1,a2,a3,a4,a5; float fang; for(i=0;i<10;i++) {for(j=0;j<5;j++) scanf("%f",score[i][j]);} ave1=meigerendepingjunfen(score[0][0],score[0][1],score[0][2],score[0][3],score[0][4]); ave2=meigerendepingjunfen(score[1][0],score[1][1],score[1][2],score[1][3],score[1][4]); ave3=meigerendepingjunfen(score[2][0],score[2][1],score[2][2],score[2][3],score[2][4]); ave4=meigerendepingjunfen(score[3][0],score[3][1],score[3][2],score[3][3],score[3][4]); ave5=meigerendepingjunfen(score[4][0],score[4][1],score[4][2],score[4][3],score[4][4]); ave6=meigerendepingjunfen(score[5][0],score[5][1],score[5][2],score[5][3],score[5][4]); ave7=meigerendepingjunfen(score[6][0],score[6][1],score[6][2],score[6][3],score[6][4]); ave8=meigerendepingjunfen(score[7][0],score[7][1],score[7][2],score[7][3],score[7][4]); ave9=meigerendepingjunfen(score[8][0],score[8][1],score[8][2],score[8][3],score[8][4]); ave10=meigerendepingjunfen(score[9][0],score[9][1],score[9][2],score[9][3],score[9][4]); printf("这十个人的平均成绩是%f\n,%f\n%,f\n,%f\n%,%f\n%,%f\n%,%f\n%,%f\n%,%f\n%,%f\n%",ave1,ave2,ave3,ave4,ave5,ave6,ave7,ave8,ave9,ave10); a1=meimenkedepingjunfen(score[0][0],score[1][0],score[2][0],score[3][0],score[4][0],score[5][0],score[6][0],score[7][0],score[8][0],score[9][0] ); a2=meimenkedepingjunfen(score[0][1],score[1][1],score[2][1],score[3][1],score[4][1],score[5][1],score[6][1],score[7][1],score[8][1],score[9][1] ); a3=meimenkedepingjunfen(score[0][2],score[1][2],score[2][2],score[3][2],score[4][2],score[5][2],score[6][2],score[7][2],score[8][2],score[9][2] ); a4=meimenkedepingjunfen(score[0][3],score[1][3],score[2][3],score[3][3],score[4][3],score[5][3],score[6][3],score[7][3],score[8][3],score[9][3] ); a5=meimenkedepingjunfen(score[0][4],score[1][4],score[2][4],score[3][4],score[4][4],score[5][4],score[6][4],score[7][4],score[8][4],score[9][4] ); printf("这几门课的平均成绩是%f,%f,%f,%f,%f",a1,a2,a3,a4,a5); fang=fangcha(ave1,ave2,ave3,ave4,ave5,ave6,ave7,ave8,ave9,ave10); printf("方差是%f",fang); h=highest(); printf("最高分:%7.2f NO.%2d coure %2d\n"); return 0;}
int main() { int i,j; float h; input_stu(); aver_stu(); aver_cour(); printf("NO. 课程1 课程2 课程3 课程4 课程5 平均\n"); for(i=0;i<N;i++) { printf("\n NO %2d",i+1); for(j=0;j<M;j++) printf("%8.2f",score[i][j]); printf("%8.2f\n",a_stu[i]); } printf("\naverage:"); for(j=0;j<M;j++) printf("%8.2f",a_cour[j]); printf("\n"); h=highest(); printf("最高分:%7.2f NO.%2d course %2d\n",h,r,c); printf("平均分方差:%8.2f\n",s_var()); return 0; }
/* * 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; }
/* * 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); } }
static constexpr range full() { return range(lowest(), highest()); }
/// Create Default as Undefined Range. range() : range(highest(), lowest()) {}
void LayeredConfiguration::add(AbstractConfiguration* pConfig, bool shared) { add(pConfig, highest(), false, shared); }
void LayeredConfiguration::add(AbstractConfiguration* pConfig) { add(pConfig, highest(), false, true); }
/// Reset to Zero (Empty). void clear() { this->first = highest(); this->second = lowest(); }
/// Undefine Prior to sucessive calls to \c include. range& undefine() { low() = highest(); high() = lowest(); return *this; }
/// Check if \em defined. bool defined() const { return (low() != highest() and high() != lowest()); }