Пример #1
0
void Topology_Sort(void) {
    int i, j;
    int Vx;

    for (i = 0; i < V; i++) {
        Indegree[i] = Selected[i] = 0;
    }

    for (i = 0; i < V; i++)
        for (j = 0; j < V; j++)
            if (M[i][j] == 1) {
                Indegree[j]++;
            }

    for (i = 0; i < V; i++) {
        Vx = choose_next();
        cout << " V" << Vx;

        for (j = 0; j < V; j++)
            if (M[Vx][j] == 1) {
                M[Vx][j] = 0;
                Indegree[j]--;
            }
    }

    cout << endl;
}
Пример #2
0
Файл: graph.c Проект: lita/opto
bool solver(int next_node_ix, int next_node_colour, Graph *g, int ncoloured) {
    bool success = set_and_propagate(next_node_ix, next_node_colour, g);
    if (!success) return false;
    else if (ncoloured == NNODES) return true;
    else {
        int next_node;
        int next_colour;
        choose_next(&next_node, &next_colour, g);
        return solver(next_node, next_colour, g, ncoloured +1);
    }
}
Пример #3
0
void topolody_sort(void)
{
    int i,j;
    int Vx;
    for (i=0;i < V;i++)
		INDEGREE[i]=SELECTED[i]=0;
    for(i=0;i < V;i++)
		for(j=0;j < V;j++)
			if(M[i][j] == 1)
				INDEGREE[j]++;

    for(i=0;i < V;i++)
    {
		Vx=choose_next();
		printf("%d",Vx);
		for(j=0;j < V;j++)
			if (M[Vx][j] == 1)
			{
				M[Vx][j]=0;
				INDEGREE[j]--;
			}
	}	
}
Пример #4
0
void Topo_Sort(void)
{
    int i,j;
    int Vx;
    for (i=0;i < S;i++)
		Indegree[i]=Selected[i]=0;
    for(i=0;i < S;i++)
		for(j=0;j < S;j++)
			if(M[i][j] == 1)
				Indegree[j]++;

    for(i=0;i < S;i++)
    {
		Vx=choose_next();
		printf(" S%d ",Vx);
		for(j=0;j < S;j++)
			if (M[Vx][j] == 1)
			{
				M[Vx][j]=0;
				Indegree[j]--;
			}
	}
	printf("\n");
}
Пример #5
0
int main( int argc, char** argv )
{
  int map_width;
  int map_height;

  int ch;

  int info_width = 38;
  int info_height;

  spacemap * map = spacemap_init();
  spaceship * bob;

  /* setup ncurses */
  
  initscr();
  start_color();

  cbreak();
  init_pair(1,COLOR_RED, COLOR_BLACK); /* for selected ship */

  info_height = map_height = LINES - 2;
  map_width   = COLS - info_width - 2;

  map->w = map_width - 1;
  map->h = map_height - 1;

  w_map = newwin( map_height, map_width, 0, 0);
  box( w_map, 0,0 );
  w_info = newwin( info_height, info_width, 0, map_width + 1 );
  box( w_info, 0,0 );

  keypad( stdscr, TRUE );
  refresh();

  timeout(50);

  /* add first ship */
  bob = new_spaceship("bob",VIPER, 5, 12 );
  bob->vx = 20;
  bob->vy = 34;
  spacemap_add( map, bob );

 
  /* game loop */
  while((ch = getch()) != KEY_F(1))
  { switch(ch)
    {
      case KEY_F(2):
      /* make a new ship */
      srand( bob->y );
      new_random_ship( map );
      break;

      case KEY_F(10):
      choose_next( map );
      break;

      case KEY_F(9):
      choose_previous( map );
      break;

      default:
      break;
    }
    wrefresh( w_map );
    wrefresh( w_info );
    /* move ships */
    clearships( map, w_map );
    moveships( map );    
    /* show ships */
    paintships( map, w_map );

    paintinfo( map, w_info );

    box( w_map, 0, 0 );

    /* game loop delay */
    timeout(100);
  }  

  endwin();

  return 0;
}