elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  BACKTRACKING CIRCUITO HAMILTONIANO
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: BACKTRACKING CIRCUITO HAMILTONIANO  (Leído 2,655 veces)
yeah_2796

Desconectado Desconectado

Mensajes: 6


Ver Perfil
BACKTRACKING CIRCUITO HAMILTONIANO
« en: 23 Mayo 2015, 01:50 am »

se trata de que leo 3 valores el primero que es la cantidad de atracciones, el segudno que son las populares (maayor nivel de diversion) y h que son aristas con las que se conectan las atracciones.

primero asi seria la entrada:

6 2 3

noria 12
mon_rusa 20
carritosCHO 100
silla_voladora 15
gusanito 1
casa_terror 13
0 1
2 1
0 2

y la salida es:

CarritosCho Mon_rusa
POSIBLE
Entrada CarritosCho Mon_rusa Entrada
Entrada Mon_rusa CarritosCho Entrada

si es imposible solo devuelve imposible

pero aparte el programa no me compila y no se si el backtracking este bien, por favor podrian ayudarme .

hola podrian ayudarme con este codigo, es un backtracking que me tiene que devolver si es posible o es imposible que haya circuito hamiltoniano

Código
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class atraccion {
  6. private:
  7. int x;
  8. string name;
  9. public:
  10.  
  11. atraccion () {}
  12. atraccion (int var, string nnombre){
  13. x=var;
  14. name = nnombre;
  15. }
  16. ~atraccion() {}
  17.  
  18. void set_x (int val) { //modifica el x
  19. x = val;
  20. }
  21.  
  22. int get_x () { //devuelve el x
  23. return x;
  24. }
  25.  
  26. void set_name ( string nom) { //modifica el nombre
  27. name =nom;
  28. }
  29.  
  30. string get_name () { //devuelve el nombre
  31. return name;
  32. }
  33. };
  34.  
  35.  
  36. void back (int i, int j, bool array[11][11],int camino[],int acum=0 , int arist){
  37.  
  38. if((j==0) && (acum= arist-1)){
  39. cout<<"POSIBLE"<<endl;
  40. }else{
  41. if (array[i][j] == true ){
  42. for (int x=0;x<11;x++){
  43. int p=j;
  44. camino[x]=j;
  45. array[i][j] = array[j][i]=false;
  46. acum=acum+1;
  47. back (i=p, j=0, array, camino, acum, arist);
  48.  
  49. camino[x] = ' '; //desmarco y deshago mu solucion
  50. acum= acum-1; //desmarco y deshago mi solucion
  51.  
  52. }
  53.  
  54. }else{
  55. back(i,j++,array,camino, acum,arist); //busco otra solucion
  56. }
  57. cout<< "IMPOSIBLE"<<endl;
  58. }
  59. }
  60.  
  61.  
  62. int main (){
  63. int m, n, h,div;
  64. int posmayor,mayor;
  65. bool mat[11][11];
  66. int x,y;
  67. string nombre;
  68. atraccion intercambio;
  69. int r=0,s=0,t=0;
  70.  
  71. cin>>m>>n>>h;
  72.  
  73. int sol[h-1];
  74. atraccion ar [m]; //arreglo que almacena cada atraccion
  75.  
  76. for (int i=0;i<m;i++) {
  77. cin>>nombre;
  78. cin>>div;
  79. ar[i].set_name(nombre);
  80. ar[i].set_x (div);
  81. }
  82.  
  83. for( int g=0;g<11;g++){ //matriz de adyacencia
  84. for (int f=0;f<11;f++){
  85. mat[g][f] =false;
  86. }
  87. }
  88.  
  89.    for (int d=0;d<=h-1;d++){           // Coloco de par en par de vértices conexos hasta que no haya más aristas
  90.            cin >> x >> y;     // Leo la pareja
  91.            mat[x][y]=mat[y][x]=true; // Guardo el dato en la matriz de adyacencia
  92.            }
  93.  
  94. for (int w=0;w<=m-2;w++){               //ordenamiento //modelo 2
  95.            posmayor = w;
  96.            mayor = ar[w].get_x();
  97.            for (int k=w+1; k<=m-1; k++){
  98. /*if ((ar[k].get_x() == mayor) && (ar[k].get_name () < ar[w].get_name())){
  99. mayor= ar[k];
  100. posmayor=k;
  101. }else{*/
  102.                if (ar[k].get_x() > mayor) {
  103.                    mayor = ar[k].get_x();
  104.                    posmayor =k;
  105. }
  106. //}
  107.            }
  108.  
  109.            intercambio = ar[posmayor]; //se encarga de cambiarlos
  110.            ar[posmayor] =ar[w];
  111.            ar[w] = intercambio;
  112. }
  113.  
  114. for (int j=0;j<n;j++) { //imprime populares
  115. cout<<ar[j].get_name()<<endl;
  116. }
  117.  
  118. for (int u=0;u<11;u++) { //imprime booleana
  119. for(int v=0;v<11;v++){
  120. cout<<mat[u][v];
  121. }
  122. }
  123. back(r, s, mat, sol, t , n);
  124.  
  125. return 0;
  126. }
  127.  
  128.  


En línea

Stakewinner00


Desconectado Desconectado

Mensajes: 1.426



Ver Perfil WWW
Re: BACKTRACKING CIRCUITO HAMILTONIANO
« Respuesta #1 en: 23 Mayo 2015, 11:19 am »

No te compila porque en la línea 36 tienes
void back (int i, int j, bool array[11][11],int camino[],int acum=0 , int arist)
cuando tendría que ser
void back (int i, int j, bool array[11][11],int camino[],int acum, int arist) o void back (int i, int j, bool array[11][11],int camino[],int acum=0 , int arist=0)
Pero como ya le pasas todos los parámetros no se si tiene mucha importancia poner esos valores por defecto.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Recursividad y Backtracking!!!!
Java
bwsr 2 8,120 Último mensaje 28 Junio 2007, 00:40 am
por bwsr
CIRCUITO TRANSMIOR Y CIRCUITO RECEPTOR DE AUDIO
Electrónica
SAHEKA_14 2 10,939 Último mensaje 20 Noviembre 2010, 01:35 am
por COMETINSONIC
Backtracking - Laberinto
Programación C/C++
hadree 3 6,692 Último mensaje 23 Noviembre 2010, 03:08 am
por do-while
[Reto] Backtracking - Laberinto
.NET (C#, VB.NET, ASP)
hadree 7 13,663 Último mensaje 17 Diciembre 2010, 13:35 pm
por pisa2
regex para email catastrophic backtracking
PHP
gAb1 4 2,850 Último mensaje 20 Abril 2016, 17:32 pm
por gAb1
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines