circle minimum_circle(vector<point> p) { circle ret; random_shuffle(p.begin(), p.end()); for (int i = 0; i < (int)p.size(); ++i) if (!in_circle(p[i], ret)) { ret = circle(p[i], 0); for (int j = 0; j < i; ++j) if (!in_circle(p[j], ret)) { ret = make_circle(p[j], p[i]); for (int k = 0; k < j; ++k) if (!in_circle(p[k], ret)) ret = make_circle(p[i], p[j], p[k]); } } return ret; }
int main(void) { int buf[MAX_BUF] = {0,}; if( !input("input.txt", buf) ) { fprintf(stderr, "ERROR: file open error or buffer overflow\n"); delete_all_memory(); exit(EXIT_FAILURE); } if(!make_stack(buf)) { fprintf(stderr, "ERROR: memory allocation failed\n"); delete_all_memory(); exit(EXIT_FAILURE); } if(!make_queue(buf)) { fprintf(stderr, "ERROR: memory allocation failed\n"); delete_all_memory(); exit(EXIT_FAILURE); } if(!make_circle(buf)) { fprintf(stderr, "ERROR: memory allocation failed or Queue size overflow\n"); delete_all_memory(); exit(EXIT_FAILURE); } output(); exit(EXIT_SUCCESS); }
int main() { init(); double length; int n, i, j; int start; int *shortest_path; int g; FILE *finput; BITMAP *city_box; KOORD *city; city_box = create_bitmap(MAKS+4, MAKS+4+16); finput = fopen("salesman_data.txt", "r"); clear_to_color(city_box, makecol(255, 255, 255)); fscanf(finput, "%d", &n); city = (KOORD*) malloc(sizeof(KOORD)*n); clear_to_color(screen, makecol(255, 255, 255)); for(i=0; i<n; i++) { fscanf(finput, "%lf %lf", &(city[i].x), &(city[i].y)); make_circle(city_box, &(city[i])); city[i].city_route = (ROUTE*) malloc(sizeof(ROUTE)*(n-1)); } generate_city_connection(city, n); shortest_path = generate_shortest_route(city, n, &start, &length); g = start; for(i=0; i<n; i++) { draw_line(city_box, &city[g], &city[city[g].city_route[shortest_path[i]].next_city]); g = city[g].city_route[shortest_path[i]].next_city; } textprintf_ex(screen, font, 10, 10, makecol( 0, 0, 0), -1, "jalan terpendek: %lf px", length); while (!key[KEY_ESC]) { draw_sprite(screen, city_box, (SCREEN_W-city_box->w)/2, (SCREEN_H-city_box->h)/2); readkey(); } for(i=0; i<n; i++) free(city[i].city_route); destroy_bitmap(city_box); fclose(finput); free(city); free(shortest_path); deinit(); return 0; }
static void random_circle_quantize_test(int seed) { auto r = new_<Random>(seed); { // First check that we can split without hitting any asserts const auto sizes = vec(1.e-3,1.e1,1.e3,1.e7); Nested<CircleArc, false> arcs; arcs.append(make_circle(Vec2(0,0),Vec2(1,0))); for(const auto& s : sizes) { for(int i = 0; i < 200; ++i) { arcs.append(make_circle(s*r->unit_ball<Vec2>(),s*r->unit_ball<Vec2>())); } } // Take the union and make sure we don't hit any asserts circle_arc_union(arcs); } { // Build a bunch of arcs that don't touch const auto log_options = vec(1.e-3,1.e-1,1.e1,1.e3); const auto max_bounds = Box<Vec2>(Vec2(0.,0.)).thickened(1.e1 * log_options.max()); const real spacing = 1e-5*max_bounds.sizes().max(); const real max_x = max_bounds.max.x; real curr_x = max_bounds.min.x; Nested<CircleArc, false> arcs; for(int i = 0; i < 50; ++i) { const real remaining = max_x - curr_x; if(remaining < spacing) break; const real log_choice = log_options[r->uniform<int>(0, log_options.size())]; real next_r = r->uniform<real>(0., min(log_choice, remaining)); arcs.append(make_circle(Vec2(curr_x, 0.),Vec2(curr_x+next_r, 0.))); curr_x += next_r + spacing; } // Take the union and make sure we don't hit any asserts auto unioned = circle_arc_union(arcs); // If range of sizes is very large, some arcs could be filtered out if they are smaller than quantization threshold... GEODE_ASSERT(unioned.size() <= arcs.size()); } }
//Generate a random map void HM::randomize(){ make_circle(50); //Calculate the normal for(int i =0;i<map_size-1;i+=1){ for(int j = 0;j<map_size-1;j+=1){ Vector3D x = height_map[i+1][j]-height_map[i][j] ; Vector3D y = height_map[i+1][j+1] - height_map[i+1][j]; Vector3D n = x.cross(y); n.normalize(); normal_map[i][j] = n; } } }