Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- class route {
- int *r, n; // r - массив, представляющий маршрут; n - кол-во городов
- public:
- route(int nn) {
- n = nn;
- r = new int[nn];
- for (int i = 0; i < n; i++) r[i] = i;
- }
- route(const route& c) {
- n = c.n;
- r = new int[c.n];
- for (int i = 0; i < n; i++) r[i] = i;
- }
- route& operator = (const route& a) {
- if (this != &a) {
- delete[] a;
- n = a.n;
- r = new int[a];
- for (int i = 0; i < n; i++) r[i] = i;
- }
- return *this;
- }
- ~route() {
- if (r != NULL) delete[] r;
- r = NULL;
- }
- int route_price(int** P) {
- if (P == NULL) return -1;
- int i = 0, S = 0;
- for (i = 0; i < n - 1; i++) {
- S = S + P[r[i]][r[i + 1]];
- }
- S = S + P[r[i]][r[0]];
- return S;
- }
- };
- int** MakeArray(int N) {
- if (N <= 0) return NULL;
- int** ptr = new int* [N];
- for (int i = 0; i < N; i++) {
- ptr[i] = new int* [N];
- for (int j = 0; j < N; j++) {
- if (i == j) ptr[i][j] = 0;
- else ptr[i][j] = 1 + rand() % 9;
- }
- }
- return ptr;
- }
- int main() {
- srand(time(NULL));
- int min = INT_MAX;
- int n = 12;
- int** P = MakeArray(n);
- route i(n), j(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment