Esempio n. 1
0
int main()
{
	int i, j;
	char c;
	char temp[20];
	scanf("%d%d\n", &cols, &rows);
	for(i = 0; i < rows; i++) 
	{
		gets(temp);
		for(j = 0; j < cols; j++)
		{
			c = temp[j];
			if(c == '.') map[i][j] = 0;
			else 
			{
				map[i][j] = c-'@';
				if (c!='X')
				{
					c -= 'A';
					site[c].x = i; 
					site[c].y = j;
				}
			}
		}
	}
	memset(factor, 0, sizeof(factor));
	char c1, c2;
	double load;
	while (1)
	{
		scanf("%c%c%lf\n", &c1, &c2, &load);
		if(c1 == 'X' && c2 == 'X') break;
		memset(steps, 255, sizeof(steps));
		memset(times, 0, sizeof(times));
		c1 -= 'A';
		c2 -= 'A';
		int dx = site[c2].x;
		int dy = site[c2].y;
		map[dx][dy] = 0;
		
		bfs_path(c1, dx, dy);
		bfs_times();

		map[dx][dy] = (++c2);
		load /= times[dx][dy];
		loadFactors(dx, dy, load);
	}
	for(i = 0; i < rows; i++) 
	{
		for(j = 0; j < cols; j++)
		{
			if (map[i][j]) factor[i][j] = 0;
			if (j) printf(" ");
			printf("%6.2lf", factor[i][j]);
		}
		printf("\n");
	}
	return(0);
}
Esempio n. 2
0
void Graph<T>::dfs(const T node, const T value)
{
  if (discovered.empty()) 
    initialize_discovered();
 
  if (path.empty() || path.top()!= node)
    path.push(node);

  if (node == value) 
    return bfs_path();
  
  if (graph.find(node) == graph.end()) 
  {
    std::cout<<"Node not found (DFS)"<<std::endl; 
    return;
  }
 
  discovered[std::distance(graph.begin(), graph.find(node))] = true;
   
  find_next_node_dfs(node, value);
}