Advertisement
Guest User

Untitled

a guest
Mar 20th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <vector>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. short TF(short In)
  8. {
  9. if(In==0)return 3;
  10. if(In==1)return 2;
  11. if(In==2)return 1;
  12. if(In==3)return 0;
  13. }
  14.  
  15. struct CH;
  16. vector <CH*> Lista;
  17.  
  18.  
  19. struct CH
  20. {
  21. CH* W[4]; int WW[4];
  22. CH* Here;
  23. short Wodory;
  24.  
  25. void DC(short Wi)
  26. {
  27. if(WW[Wi]!=0)return;
  28. W[Wi]=new CH;
  29. WW[Wi]=-3;
  30. Lista.push_back(W[Wi]);
  31. W[Wi]->WW[0]=0;W[Wi]->W[0]=0;
  32. W[Wi]->WW[1]=0;W[Wi]->W[1]=0;
  33. W[Wi]->WW[2]=0;W[Wi]->W[2]=0;
  34. W[Wi]->WW[3]=0;W[Wi]->W[3]=0;
  35. if(Wi==0){W[Wi]->W[3]=Here;W[Wi]->WW[3]=-3;}
  36. if(Wi==1){W[Wi]->W[2]=Here;W[Wi]->WW[2]=-3;}
  37. if(Wi==2){W[Wi]->W[1]=Here;W[Wi]->WW[1]=-3;}
  38. if(Wi==3){W[Wi]->W[0]=Here;W[Wi]->WW[0]=-3;}
  39. W[Wi]->Wodory=3; Wodory--;
  40. }
  41.  
  42. int UDroge(short Wi)
  43. {
  44. int Max=0;int N;
  45. for(N=0;N<4;N++)
  46. {
  47. if(Wi!=N)
  48. {
  49. if(WW[N]==-3)
  50. WW[N]=W[N]->UDroge(TF(N))+1;
  51. if(WW[N]>Max)
  52. Max=WW[N];
  53. }
  54. }
  55. return Max;
  56. }
  57. };
  58.  
  59.  
  60.  
  61.  
  62.  
  63. int main()
  64. {
  65. CH Czastka;
  66. Czastka.Here=&Czastka;
  67. Czastka.Wodory=4;
  68. Lista.push_back(&Czastka);
  69. Czastka.W[0]=0;
  70. Czastka.W[1]=0;
  71. Czastka.W[2]=0;
  72. Czastka.W[3]=0;
  73. Czastka.WW[0]=0;
  74. Czastka.WW[1]=0;
  75. Czastka.WW[2]=0;
  76. Czastka.WW[3]=0;
  77.  
  78.  
  79. Czastka.DC(0);
  80. Czastka.W[0]->DC(0);
  81. Czastka.W[0]->W[0]->DC(1);
  82. Czastka.W[0]->W[0]->DC(0);
  83. Czastka.W[0]->W[0]->W[0]->DC(0);
  84. Czastka.W[0]->W[0]->W[0]->W[0]->DC(0);
  85.  
  86.  
  87.  
  88. int I=0;
  89. int A=0;
  90. int Max=0;
  91. for(I=Lista.size()-1;I>=0;I--)
  92. if(Lista[I]->Wodory>=3)
  93. {
  94. for(A=0;A<4;A++)if(Lista[I]->WW[A]!=0)
  95. {
  96. Lista[I]->WW[A]=Lista[I]->UDroge(int(sqrt((A-1)*(A-1))));
  97. if(Max<Lista[I]->WW[A])Max=Lista[I]->WW[A];
  98. }
  99. }
  100. cout<<Max;
  101. int Wegle;
  102.  
  103. getch();
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement