当前位置: 首页>>代码示例>>C++>>正文


C++ printSolution函数代码示例

本文整理汇总了C++中printSolution函数的典型用法代码示例。如果您正苦于以下问题:C++ printSolution函数的具体用法?C++ printSolution怎么用?C++ printSolution使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了printSolution函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: printSolution

void LongestCommonSubsequence::printSolution(int begin, int end) const
{
	if (b[begin-1][end-1] == 'd') {
		printSolution(begin - 1, end - 1);
		std::cout << " " << X[begin-1];
	}
	else if (b[begin-1][end-1] == 't') {
		printSolution(begin - 1, end);
	}
	else if (b[begin - 1][end - 1] == 'l') {
		printSolution(begin, end - 1);
	}
}
开发者ID:qwyster,项目名称:RodCutting,代码行数:13,代码来源:LongestCommonSubsequence.cpp

示例2: printSolution

/* Извежда резултата на екрана */
void printSolution(int x, int y)
{ if (x > 0 && y > 0 && F[x][y].value > 0) {
    if (F[x][y].action > 0) {
      printSolution(F[x][y].action, y);
      printSolution(x - F[x][y].action, y);
    }
    else if (F[x][y].action < 0) {
      printSolution(x, -F[x][y].action);
      printSolution(x, y - (-F[x][y].action));
    }
    else
      printf("(%2u,%2u) --> %2u  ", x, y, F[x][y].value);
  }
}
开发者ID:gbonevska,项目名称:ProgrammingEqualsPlusPlusAlgorithms,代码行数:15,代码来源:cuts.c

示例3: must_search_for_other_solutions

       bool must_search_for_other_solutions(Node const& p, Robot::names r_)
       {
           if (m_solutions[r_].nrj() == 0) // new solution
           {
               {
                   this->m_stats.printSituationSoFar(true);
                   std::cout << "\nGOAL reached for " << Robot::toString(r_) << " in " << p.nrj() << " moves" << ": " <<std::flush;
                   // print solution
#if 0
                   Node last=p;
                   while (true)
                   {
                       std::cout << "\n <- " << last << std::flush;
                       const Set::iterator wh = this->m_seen.find(last.m_previous);
                       if (wh == this->m_seen.end()) break;
                       std::cout << "[" 
                           << Robot::toString(last.link().robot()) << Directions::toString(last.link().direction())
                           << "]" << std::flush;
                       last = *wh;
                   }
                   std::cout << std::endl;
#endif

                   printSolution(p, this->previous(), Robot::MAX__);
                   std::cout << "\n" << std::endl;
               }

               m_solutions[r_] = p;
               for (Robot::names r=Robot::names(0) ; r!=Robot::MAX__; ++r)
                   if (m_solutions[r].nrj()==0)
                       return true;
               return false;
           }
           return true;
       }
开发者ID:LucHermitte,项目名称:Rasende,代码行数:35,代码来源:explore-hash.hpp

示例4: printSolution

int BreadthFirstSearch::returnSolution(const string & start, const string & end,  string & sol)
{
	int startIndex=AdjacencyMatrix.getNameIndex(start);
	int endIndex=AdjacencyMatrix.getNameIndex(end);
	queue.push(startIndex);
	AdjacencyMatrix.getVertex(startIndex).color=GREY;
	if(BFS(endIndex))
	{
		cout<<"BFS solution found\n";
		printSolution(endIndex,sol);
		sol.erase(sol.end()-1);
	}

	ofstream bfsOutputFile(outputFileName.c_str(),ios::out);
	if (!bfsOutputFile)
	{
		cerr << "Uh oh, " << outputFileName << " could not be opened for writing!" << endl;
		exit(1);
	}
	
	bfsOutputFile<<sol;
	bfsOutputFile.close();


	return 1;
}
开发者ID:nittoor,项目名称:Uninformed-Search,代码行数:26,代码来源:BreadthFirstSearch.cpp

示例5: dijkstra

void dijkstra(int graph[V][V], int src)
{
    int dist[V];
    
    bool sptSet[V];
    
    for(int i=0; i<V; i++)
        dist[i] = INT_MAX, sptSet[i] = false;
    
    dist[src] = 0;
    
    for(int count =0; count < V-1; count++)
    {
        int u = minDistance(dist, sptSet);
        sptSet[u] = true;
        
        for(int v=0; v<V; v++)
            if(!sptSet[v] && graph[u][v] 
            && dist[u] != INT_MAX 
            && dist[u] + graph[u][v] < dist[v])
                dist[v]  = dist[u] + graph[u][v];
    }
    
    printSolution(dist, V);
}
开发者ID:csseryang,项目名称:csseryang,代码行数:25,代码来源:dijsktra_matrix.cpp

示例6: printSolution

int DepthFirstSearch::returnSolution(const string & start, const string & end, string & sol)
{
	int startIndex=AdjacencyMatrix.getNameIndex(start);
	int endIndex=AdjacencyMatrix.getNameIndex(end);
	
	if (DFS(startIndex,endIndex))
	{
		cout<<"DFS solution found!\n";
		printSolution(endIndex,sol);
		sol.erase(sol.end()-1);
	}

	ofstream dfsOutputFile(outputFileName.c_str(),ios::out);
	if (!dfsOutputFile)
	{
		cerr << "Uh oh, " << outputFileName << " could not be opened for writing!" << endl;
		exit(1);
	}
	
	dfsOutputFile<<sol;
	dfsOutputFile.close();

	return 1;
	
}
开发者ID:nittoor,项目名称:Uninformed-Search,代码行数:25,代码来源:DepthFirstSearch.cpp

示例7: solve

// Main recursive function used to solve the program
int solve(int step, cell_t* myCells, constraint_t* myConstraints,
          long long* myNodeCount) {
  int cellIndex;
  int value = UNASSIGNED_VALUE;

  if (found)
    return 1;

  if (step == totalNumCells) {
    // Print out solution and set found to true
    #pragma omp critical
    {
      if (!found) {
        printSolution(myCells);
        found = 1;
      }
    }

    return 1;
  }

  (*myNodeCount)++;
  // Find the next cell to fill and test all possible values
  if ((cellIndex = getNextCellToFill(myCells, myConstraints)) < 0)
    return 0;

  while (UNASSIGNED_VALUE != (value = applyNextValue(myCells, myConstraints,
                                                     cellIndex, value))) {
    if (solve(step + 1, myCells, myConstraints, myNodeCount))
      return 1;
  }

  return 0;
}
开发者ID:bparr,项目名称:KenKen-Solver,代码行数:35,代码来源:parallel.c

示例8: main

int main(void) { 
  init();
  printf("\nМаксимална цена %u", solve(sizeX, sizeY));
  printf("\nРазмери (X,Y)-->Цена\n");
  printSolution(sizeX, sizeY);
  return 0;
}
开发者ID:gbonevska,项目名称:ProgrammingEqualsPlusPlusAlgorithms,代码行数:7,代码来源:cuts.c

示例9: back

void back() {

     int HS;

     init();

     while(level > 0) {

           do{}while((HS=has_next()) && !isValid()); 

           if( HS ) {

             if(solution()) {

                printSolution();

             } else {

                level = level + 1;
                init(); 

             }

           } else {

             level = level - 1;
           }
     }
}
开发者ID:thinkphp,项目名称:hamiltonian-path,代码行数:29,代码来源:hamiltonian-path.c

示例10: main

int main(){
	int resultanceMatrix[MAXVERTEX][MAXVERTEX][MAXVERTEX];
	int n, m;
  int origin, master, distance, lookTrip, cityDistance, test = 0;
  
  while(scanf("%d %d", &n, &m) != EOF){
	  if(test >= 1)
      printf("\n");
    test++;

	  initialize(resultanceMatrix, n);

	  for(int i = 0; i < m; i++){
	    scanf("%d %d %d", &origin, &master, &distance);
	    if(resultanceMatrix[0][origin][master] > distance)
	    	resultanceMatrix[0][origin][master] = distance;
	  }

		floydWarshall(resultanceMatrix,n);

		printf("Instancia %d\n", test);
    scanf("%d", &lookTrip);
    for(int i = 0; i < lookTrip;i++){
      scanf(" %d %d %d", &origin, &master, &cityDistance);
      printSolution(resultanceMatrix,origin,master,cityDistance,n);
    }
	}
	return 0;
}
开发者ID:DiegoCorrea,项目名称:graphTheory,代码行数:29,代码来源:MINIMO_warshall.cpp

示例11: solveTour

void solveTour(int &sizeX, int &sizeY, int &startX, int &startY)
{
	/* Create an array that will contain the solution */
	// allocate the solution array
	int** solution = new int*[sizeX];
	for (int i = 0; i < sizeX; i++)
		solution[i] = new int[sizeY];

	/* Set all position to -1 */
	for (int x = 0; x < sizeX; x++)
		for (int y = 0; y < sizeY; y++)
			solution[x][y] = -1;

	/* All 8 of the possible move options for the knight */
	int xMove[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
	int yMove[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };

	/* Knight will start and the square chosen by the user */
	solution[startX][startY] = 0;

	/* Start at current position and from there explore all tours using exploreTours() */
	if (exploreTours(sizeX, sizeY, startX, startY, 1, solution, xMove, yMove) == false)
	{
		printf("No solution found");
	} else {
		printSolution(sizeX, sizeY, solution);
		printf("\n\nsolved!\n");
	}

}
开发者ID:voxellotl,项目名称:knights-tour-backtracking,代码行数:30,代码来源:solve.cpp

示例12: solveKTUtil

/* This function solves the Knight Tour problem using Backtracking.  This
function mainly uses solveKTUtil() to solve the problem. It returns false if
no complete tour is possible, otherwise return true and prints the tour.
Please note that there may be more than one solutions, this function
prints one of the feasible solutions.  */
bool solveKT()
{
    int sol[N][N];
 
    /* Initialization of solution matrix */
    for (int x = 0; x < N; x++)
        for (int y = 0; y < N; y++)
            sol[x][y] = -1;
 
    /* xMove[] and yMove[] define next move of Knight.
       xMove[] is for next value of x coordinate
       yMove[] is for next value of y coordinate */
    int xMove[8] = {  2, 1, -1, -2, -2, -1,  1,  2 };
    int yMove[8] = {  1, 2,  2,  1, -1, -2, -2, -1 };
 
    // Since the Knight is initially at the first block
    sol[0][0]  = 0;
 
    /* Start from 0,0 and explore all tours using solveKTUtil() */
    if(solveKTUtil(0, 0, 1, sol, xMove, yMove) == false)
    {
        printf("Solution does not exist");
        return false;
    }
    else
        printSolution(sol);
 
    return true;
}
开发者ID:pango89,项目名称:IDEONE,代码行数:34,代码来源:Knight's_Tour.cpp

示例13: printPuzzle

void printPuzzle(Puzzle *puzzle) {
    int i, j, size = puzzle->size;
    printf("\n\nDificulty: %d x %d\n", size, size);
    printf("Shuffles: %d\n\n", shuffleCount);
    
    printBorder(size);
    
    for (i = 0; i < size; i++) {
        printf("%5c#|", ' ');
        for (j = 0; j < size; j++) {
            if(puzzle->matrix[i][j] == 0) {
                if(puzzle->inverted)
                    printf("%2c", ' ');
                else
                    printf("%2d", 0);
            } else {
                printf("%2d", puzzle->matrix[i][j]);
            }
            printf("|");
        }
        printf("#\n");
    }
    
    printBorder(size);
    printMenu();
    
    if(showSolution && puzzle->solution->size > 0)
        printSolution(puzzle->solution);
}
开发者ID:jeongsuhyun,项目名称:slide-puzzle-c,代码行数:29,代码来源:interface.c

示例14: santaVisit

void santaVisit(int current, int depth)
{
	candidate[depth] = current;

	if (depth == 8)
	{
		printSolution();
		return;
	}

	for (int i = 1; i <= 5; i++)
	{
		// if connected and not visited yet
		if (house[current][i] && !edgeVisited[current][i])
		{
			edgeVisited[current][i] = true; // mark this edge visited
			edgeVisited[i][current] = true; // mark this edge visited, bidirectional 

			santaVisit(i, depth + 1);

			// backtrack
			edgeVisited[current][i] = false; // undo this edge visited
			edgeVisited[i][current] = false; // undo this edge visited, bidirectional 
		}
	}
}
开发者ID:welly87,项目名称:uva_solutions,代码行数:26,代码来源:Source.cpp

示例15: main

int main(int argc, char *argv[]){

	int start, goal, d, nodeCount = 0;
	
	if (argc < 3) {
		fprintf(stderr, "Usage: %s start goal [-verbose/-v]\n", argv[0]);
		return EXIT_FAILURE;
	}

	if (argc == 4 && (strcmp(argv[3], "-v") == 0 || strcmp(argv[3], "-verbose") == 0)){
		verbose = 1;
	}

	start = atoi(argv[1]);
	goal = atoi(argv[2]);

	printf("Problem: route from %d to %d\n\n", start, goal);

	d = ids(start, goal, &nodeCount);

	if (d >= 0){
		printSolution(start, d, nodeCount);
	}

	else {
		printf("Solution not found.\n");
	}

	return 0;
}
开发者ID:dududcbier,项目名称:AI,代码行数:30,代码来源:ids.c


注:本文中的printSolution函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。