示例#1
0
文件: 208.cpp 项目: Quinny/qdw-acm
unsigned paths(directed_graph<unsigned> g, directed_graph<unsigned> floyd, unsigned n) {
    unsigned paths = 0;
    std::vector<unsigned> path;
    std::set<unsigned> visited;

    path.push_back(1U);
    visited.insert(1U);

    print_paths(g, floyd, path, visited, 1U, n, paths);
    return paths;
}
示例#2
0
文件: tcc.c 项目: raldoni/tcc
static void display_info(TCCState *s, int what)
{
    switch (what) {
    case 0:
        printf("tcc version %s ("
#ifdef TCC_TARGET_I386
        "i386"
#elif defined TCC_TARGET_X86_64
        "x86-64"
#elif defined TCC_TARGET_C67
        "C67"
#elif defined TCC_TARGET_ARM
        "ARM"
# ifdef TCC_ARM_HARDFLOAT
        " Hard Float"
# endif
#elif defined TCC_TARGET_ARM64
        "AArch64"
# ifdef TCC_ARM_HARDFLOAT
        " Hard Float"
# endif
#endif
#ifdef TCC_TARGET_PE
        " Windows"
#else
        " Linux"
#endif
        ")\n", TCC_VERSION);
        break;
    case 1:
        printf("install: %s\n", s->tcc_lib_path);
        /* print_paths("programs", NULL, 0); */
        print_paths("include", s->sysinclude_paths, s->nb_sysinclude_paths);
        print_paths("libraries", s->library_paths, s->nb_library_paths);
#ifndef TCC_TARGET_PE
        print_paths("crt", s->crt_paths, s->nb_crt_paths);
        printf("elfinterp:\n  %s\n",  DEFAULT_ELFINTERP(s));
#endif
        break;
    }
}
示例#3
0
文件: bt.c 项目: shylesh/mycode
int main()
{

	char ch;
	int ele;
	struct node *root = NULL;
	int num;
	int depth = 0;
	int ret;

	while(1) {
		printf ("I/i to insert\n");
		printf ("P/p to print\n");
		printf ("C/c to count\n");
		printf ("D/d to max_depth\n");

		scanf (" %c", &ch);
		switch(ch) {
		case 'i': case 'I': 
			printf ("enter ele\n");
			scanf("%d", &ele);	
			root = insert(root, ele);
			break;

		case 'p': case 'P':
			print_tree(root);
			break;
		case 'c': case 'C':
			num = size(root);
			printf ("number of nodes = %d\n", num);		
			break;
		case 'd':
			depth = max_depth(root);
			printf ("max depth is %d\n", depth);
			break;	
		case 's':
			ret = has_path_sum (root, 10);
			if (ret == FOUND)
				printf ("found\n");
			else if (ret == NOT_FOUND)
				printf ("not found \n");
			else
				printf ("unknown\n");
			break;
		case 't':
			print_paths (root);
			break;

		default: printf ("pls provide proper input\n");
		}
	}
}	
示例#4
0
int main(int argc, char *argv[])
{
	struct bitree *tree;
	int cnt;

	tree = build(DEFAULT_TREE_SIZE);
	if (!tree) {
		fprintf(stderr, "build tree error\n");
		exit(EXIT_FAILURE);
	}

	traverse_dump(tree, TRAVE_PREORDER);

	traverse_dump(tree, TRAVE_INORDER);

	traverse_dump(tree, TRAVE_POSTORDER);

	traverse_dump(tree, TRAVE_LEVELORDER);

	fprintf(stdout, "\nmirroring the tree\n");
	mirror(tree->root);
	traverse_dump(tree, TRAVE_LEVELORDER);
	mirror(tree->root); /* reverse */

	fprintf(stdout, "\ndoubling the tree\n");
	double_tree(tree);
	traverse_dump(tree, TRAVE_LEVELORDER);
	traverse_dump(tree, TRAVE_INORDER);
	traverse_dump(tree, TRAVE_PREORDER);

	cnt = print_paths(tree->root);
	fprintf(stdout, "total %d paths\n", cnt);


exit:
	if (visit_list)
		dlist_destroy(visit_list);
	free(bitree_root(tree)->data);
	bitree_destroy(tree);
	free(tree);

	exit(EXIT_SUCCESS);
}
示例#5
0
/* Extract all files in an archive to the filesystem under the path given by
 * dest. Returns 0 on success or <0 on error.
 */
static int extract_all(struct archive *a, const char *dest, int flags)
{
    struct archive *disk;
    struct archive_entry *entry;
    int r;
    int eof;

    disk = open_disk(flags);
    if (!disk)
        return -1;

    while (1) {
        entry = read_header(a, &eof);
        if (eof)
            break;
        if (!entry) {
            r = -1;
            goto err_cleanup;
        }

        r = transform_all_paths(entry, dest);
        if (r == 1)
            continue;
        if (r < 0) {
            opkg_msg(ERROR, "Failed to transform path.\n");
            goto err_cleanup;
        }

        print_paths(entry);

        r = extract_entry(a, entry, disk);
        if (r < 0)
            goto err_cleanup;
    }

    r = ARCHIVE_OK;
 err_cleanup:
    archive_write_free(disk);
    return (r == ARCHIVE_OK) ? 0 : -1;
}
示例#6
0
文件: 208.cpp 项目: Quinny/qdw-acm
void print_paths(
    directed_graph<unsigned> g,
    directed_graph<unsigned> floyd,
    std::vector<unsigned> path,
    std::set<unsigned> visited,
    unsigned cur,
    unsigned end,
    unsigned& paths
) {
    if (cur == end) {
        ++paths;
        for (unsigned i = 0; i != path.size(); ++i) {
            if (i)
                std::cout << ' ';
            std::cout << path[i];
        }
        std::cout << std::endl;
        return;
    }

    for (unsigned i = 1; i <= max; ++i) {
        if (visited.find(i) != visited.end())
            continue;
        if (!g.connected(cur, i))
            continue;
        if (!floyd.connected(i, end))
            continue;

        path.push_back(i);
        visited.insert(i);

        print_paths(g, floyd, path, visited, i, end, paths);

        path.erase(std::prev(path.end()));
        visited.erase(i);
    }
}
示例#7
0
文件: utemp.c 项目: rubund/graywolf
void utemp()
{

INT check ;
unsigned i2 ;
INT i , freeze ;


if( orientation_optimizationG ) {
    pairtestG = TRUE ;
}

fraction_doneG = 0.0 ;

check = 0 ;
freeze = 10000000 ;
init_table() ;


attprcelG = compute_attprcel(1);

if( pairtestG == 0 ) {
    attmaxG = attprcelG * moveable_cellsG ;

    if( iterationG < 1 ) {
	resume_runG = 0 ;
    }
    if( !resume_runG && !good_initial_placementG ) {
	from_beginning() ;
    } else if( resume_runG ) {
	from_middle() ;
    }
}

for( ; ; ) {
    if( pairtestG == FALSE && TG >= 0.01 ) {
	uloop() ;
	savewolf(0) ; 
    } else {
	D( "twsc/after_annealing", 
	    G( process_graphics() ) ;
	) ;
	pairtestG = TRUE ;
	if( check == 0 ) {
	    check = 1 ;

	    savewolf(0) ;
	    freeze = iterationG ;

	    if( connection_machineG == TRUE ) {
		findunlap(0) ;
		outcm() ;
	    }

	    findunlap(0) ;
#ifndef MITLL
	    if( SGGRG || (!doglobalG) ) {
		even_the_rows(0,FALSE) ;
		M( MSG, NULL,"evening the row lengths\n") ;
		findunlap(0) ;
	    }
#else
	    if( check_row_lengths() ) {
		gate_array_even_the_rows(0) ;
		M( MSG, NULL,"evening the row lengths\n") ;
		findunlap(0) ;
	
		for( i = 1 ; i <= 5 ; i++ ) {
		    if( check_row_lengths() ) {
			sprintf(YmsgG,"evening the row lengths %d\n",
							    i+1) ;
			M( MSG, NULL, YmsgG ) ;
			even_the_rows_2( i ) ;
			findunlap(0) ;
		    }
		}
	    }
#endif
	    penaltyG = 0 ;
	    /*
	     *  This computes new wire costs for the compacted
	     *  placement (and feed insertion).  It calls unlap()
	     *  which sorts and places the cells end-to-end
	     */
	    M( MSG, NULL,"Removed the cell overlaps --- ");
	    M( MSG, NULL,"Will do neighbor interchanges only now\n");
	    sprintf( YmsgG, "\nTOTAL INTERCONNECT LENGTH: %d\n",funccostG);
	    M( MSG, NULL, YmsgG ) ;
	    sprintf(YmsgG,"initialRowControl:%8.3f\n", initialRowControlG);
	    M( MSG, NULL, YmsgG ) ;
	    sprintf(YmsgG,"finalRowControl:%8.3f\n", finalRowControlG);
	    M( MSG, NULL, YmsgG ) ;
	    fflush(fpoG);

	    attmaxG = 5 * moveable_cellsG ;
	    if( noPairsG == 0 ) {
		TG = 0.001 ;
		M(  MSG, NULL, "iter      T      Wire accept Time\n" ) ;
		upair() ;
		savewolf(1) ;
	    }
	} else {
	    if( noPairsG == 0 ) {
		TG = 0.001 ;
		upair() ;
		savewolf(1) ;
	    }
	}
	print_paths() ;
    }

    if(!(Ymessage_get_mode() )){
	/* if we aren't dumping everything to the screen */
	/* show iteration number */
	USER_INCR_METER() ;
	printf("%3d ", iterationG );
	if( iterationG % 15 == 0 ) {
	    printf("\n");
	}
    }
    ++iterationG;
    fflush( stdout ) ;
    G( check_graphics(TRUE) ) ;

    if( iterationG >= freeze + 3 ) {

	ASSERT( dprint_error(), NULL, NULL ) ;
	if( doglobalG ) {
	    execute_global_router() ;
	} else {
	    findunlap(0) ;
	    output() ; 
	}
	sprintf(YmsgG,"FINAL TOTAL INTERCONNECT LENGTH: %d\n",funccostG);
	M( MSG, NULL, YmsgG ) ;
	sprintf(YmsgG,"FINAL OVERLAP PENALTY: %d    ", penaltyG );
	M( MSG, NULL, YmsgG ) ;
	sprintf(YmsgG, "FINAL VALUE OF TOTAL COST IS: %d\n", 
					    funccostG + penaltyG ) ;
	M( MSG, NULL, YmsgG ) ;
	sprintf(YmsgG,"MAX NUMBER OF ATTEMPTED FLIPS PER T:%8d\n",attmaxG);
	M( MSG, NULL, YmsgG ) ;
	break ;
    } 
}
示例#8
0
finalout()
{

INT c ;
INT bbtop, bbbottom, bbleft, bbright ;

/* dump the results of the placement to graphics file */
G( graphics_dump() ) ;
G( TWsetMode(1) ) ;
G( draw_the_data() ) ;
G( TWsetMode(0) ) ;


/* we known wire area at this point don't need to estimate */
turn_wireest_on(FALSE) ;

/* let the user know which pins we couldn't place */
set_pin_verbosity( TRUE ) ;

/* before channel graph generation and global routing let use tweak */
/* placement if desired */
if( doGraphicsG && wait_for_userG ){
    G( TWmessage( "TimberWolfMC waiting for your response" ) ) ;
    G( process_graphics() ) ;
} 

savewolf( TRUE ) ;  /* for debug purposes force save to occur */
if( scale_dataG > 1 ){
    /* end of the line for scaled case - 
	will return to parent to continue using saved placement. */
    closegraphics() ;
    YexitPgm( PGMOK ) ;
}
grid_cells() ;      /* force cells to grid locations */
compact(VIOLATIONSONLY); /* remove cell overlap */

/* if this is a partitioning run determine row placement */
if( doPartitionG && !(quickrouteG) ){
    set_determine_side( FALSE ) ;  /* allow SC to pick side */
    G( set_graphic_context( PARTITION_PLACEMENT ) ) ;
    config_rows() ;
    print_paths() ; /* print path information */
    Output( 0 ) ;
    return ;
}
/* do final placement of pads using virtual core to insure pads */
/* are outside of core */
setVirtualCore( TRUE ) ;
placepads() ;

/* before channel graph generation and global routing let use tweak */
/* placement if desired */
check_graphics() ;

if( !scale_dataG ){ 
    /* reload bins to get new overlap penalty */
    loadbins(FALSE) ; /* wireArea not known */
}
prnt_cost( "\nFINAL PLACEMENT RESULTS AFTER VIOLATION REMOVAL ARE:\n" ) ;

print_paths() ; /* print path information */
Output( 0 ) ;

if( doCompactionG > 0 || quickrouteG ) {
    gmain( CHANNELGRAPH ) ;
    rmain( NOCONSTRAINTS ) ;
    gmain( UPDATE_ROUTING ) ;
    adapt_wire_estimator() ;
    check_graphics() ;

    if( quickrouteG ){
	return ;
    }

    for( c = 1 ; c <= doCompactionG ; c++ ) {

	funccostG = findcost() ;
	sprintf(YmsgG,"\n\nCompactor Pass Number: %d begins with:\n", c ) ;
	prnt_cost( YmsgG ) ;

	wirecosts() ;


	grid_cells() ;      /* force cells to grid locations */
	compact(COMPACT);   /* remove white space */
	reorigin() ;
	check_graphics() ;

	sprintf(YmsgG,"\n\nCompactor Pass Number: %d after cost:\n", c ) ;
	prnt_cost( YmsgG ) ;

	Output( c ) ;

	gmain( CHANNELGRAPH ) ;

	if( c == doCompactionG ){
	    rmain( CONSTRAINTS ) ;
	} else {
	    rmain( NOCONSTRAINTS ) ;
	    gmain( UPDATE_ROUTING ) ;
	    adapt_wire_estimator() ;
	    check_graphics() ;
	}

    } /* end compaction - global route loop */

} else {
    if( doChannelGraphG ) {
	gmain( CHANNELGRAPH ) ;
    }
    if( doGlobalRouteG ) {
	rmain( CONSTRAINTS ) ;
    }
}


prnt_cost("\nTIMBERWOLFMC FINAL RESULTS ARE:\n" ) ;

return ;
} /* end finalout */
int main(int argc, char **argv){
    int num_vertices = 0;
    int num_edges = 0;
    int i;                  // counter to loop through parameters
    int print = 0;          // print resulting adjacency matrix?
    int oriented = 0;       // whether or not the random matrix is oriented
    int **matrix;           // adjacency matrix
    int **parent_matrix;    // matrix used to restore paths
    int num_bad_edges = 0;  // number of bad edges in file
    int total_distance;
    int diameter;
    char filename[100];     // filename if given as param

    struct timeval start, end;
    double time;


    // print usage
    usage();

    // read params
    for(i=1; i<argc; i++){
        if(strcmp(argv[i], "-print") == 0){
            print = 1;
        } else if(strcmp(argv[i], "-read") == 0){
            // assume filename is not longer than 100 chars
            strcpy(filename, argv[++i]);
        } else if(strcmp(argv[i], "-random") == 0){
            num_vertices = atoi(argv[++i]);
            oriented = atoi(argv[++i]);
        } else {
            num_vertices = 4000;
            oriented = 1;
        }
    }

    if(num_vertices > 0){
        // init random adjacency matrix for testing
        total_distance = init_random_adjacency_matrix(num_vertices, &num_edges, &matrix, &parent_matrix, oriented);
    } else {
        // generate adjacency matrix from file
        total_distance = read_adjacency_matrix(filename, &num_vertices, &num_edges, &matrix, &parent_matrix, &oriented, &num_bad_edges);
    }

    fprintf(stderr, "Running ASP with %d rows and %d edges (%d are bad)\n", num_vertices, num_edges, num_bad_edges);

    if(gettimeofday(&start, 0) != 0){
        fprintf(stderr, "Error starting timer\n");
        exit(EXIT_FAILURE);
    }

    floyd_warshall(matrix, parent_matrix, num_vertices);

    diameter = calculate_diameter(matrix, num_vertices);

    if(gettimeofday(&end, 0) != 0){
        fprintf(stderr, "Error stopping timer\n");
        exit(EXIT_FAILURE);
    }

    time = (end.tv_sec + end.tv_usec / 1000000.0) -
            (start.tv_sec + start.tv_usec / 1000000.0);


    fprintf(stderr, "Total distance: %d\n", total_distance);
    fprintf(stderr, "Diameter: %d\n", diameter);
    fprintf(stderr, "ASP took %10.3f seconds\n", time);

    if(print){
        print_paths(matrix, parent_matrix, num_vertices);
    }

    free_matrix(matrix, num_vertices);
    free_matrix(parent_matrix, num_vertices);

    return 0;
}