- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
//Башня хаханойская
#include <iostream>
#include<ctime>
#include<math.h>
using namespace std;
int count=0;
void hanoi_towers(int quantity, int from, int to, int buf_peg)
{
int mass[10];
if (quantity != 0)
{
hanoi_towers(quantity-1, from, buf_peg, to);
for (int i = 0; i < quantity; i++) {
mass[i]=1+rand()%quantity;
cout <<" ["<<i<<"]="<<mass[i]<<endl;}
cout <<"S kol'ca # "<< from << " na kol'co # " << to << endl;
hanoi_towers(quantity-1, buf_peg, to, from);
count++;
}
}
int main()
{
int mas[10];
int start_peg = 1, destination_peg=3, buffer_peg=2, plate_quantity,p;
cout << "Koli4estvo discov:" << endl;
cin >> plate_quantity;
for (int i = 0; i < plate_quantity; i++) {
mas[i]=i;
cout <<"1 massiv=["<<i<<"]="<<mas[i]<<endl;}
hanoi_towers(plate_quantity, start_peg, destination_peg, buffer_peg);
cout<<"Kol. iteracui = "<<count<<endl;
p=pow(2.0,plate_quantity)-1 ;
cout<<"Po formule ="<<p<<endl;
for (int i = 0; i < plate_quantity; i++) {
cout <<"3 massiv=["<<i<<"]="<<mas[i]<<endl;
}
getchar();
getchar();
}
Gerchicov-bp 07.05.2015 14:55 # −1
bormand 07.05.2015 16:03 # 0
bormand 07.05.2015 16:27 # +3
inkanus-gray 07.05.2015 16:28 # 0