예제 #1
0
void write()
{
     if (!m)
     {
        printf("%d\n%d\n",1,1);
        return;
     }
     int L=0*XX,R=m*XX,best;
     do
     {
       int mid=(L+R)>>1;
       build_network(mid);
       int g=m*XX-sap();
       if (g<=0) R=mid;
       else L=mid,best=L;
     }
     while (L+1!=R);
     build_network(best);
     sap();
     dfs(S);
     for (int i=0;i<n;i++)
         if (!visited[i]) total++;
     printf("%d\n",total);
     for (int i=0;i<n;i++)
         if (!visited[i])
            printf("%d\n",i+1);
}
예제 #2
0
파일: main.c 프로젝트: HsiehYuho/DESProgram
int main(int argc, const char * argv[]) {
    // insert code here...
    if(argc != 5){
        printf("Please pass required arguement with required sequence into program. \n");
        printf("cpssim Time config.txt stats.txt log.txt \n");
        return 1;
    }
    
    double time_limit = atof(argv[1]);
    FILE* config_file = fopen(argv[2], "r");
    FILE* stats_file = fopen(argv[3], "a");
    FILE* log_file = fopen(argv[4], "a");

    if(config_file == NULL || stats_file == NULL || log_file == NULL){
        printf("Read/Write files fails. \n");
        return 1;
    }
    
    bool result = build_network(config_file,stats_file , log_file);
    if(result){
        printf("Build sucess! \n");
        run_sim(time_limit);
    }
    else{
        printf("Build fail! \n");
    }
    
    fclose(config_file);
    fclose(log_file);
    fclose(stats_file);
    printf("Finish!\n");
    
    return 0;
}
예제 #3
0
파일: map.c 프로젝트: jquick/pioneers
static Hex *hex_new(Map * map, gint x, gint y)
{
	Hex *hex;

	g_assert(map != NULL);
	g_assert(x >= 0);
	g_assert(x < map->x_size);
	g_assert(y >= 0);
	g_assert(y < map->y_size);
	g_assert(map->grid[y][x] == NULL);

	hex = g_malloc0(sizeof(*hex));
	map->grid[y][x] = hex;

	hex->map = map;
	hex->x = x;
	hex->y = y;
	build_network(hex, NULL);
	connect_network(hex, NULL);
	return hex;
}