Racja!
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cstddef>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;
class Item
{
private:
int time, dist, index, deadline;
public:
Item(int time=0, int dist=0, int index=0, int deadline=0):time(time),dist(dist), index(index), deadline(deadline) {}
int Time()const { return time; } //a
int Dist()const { return dist; } //b
int Index()const { return index; } //c
int Deadline()const { return deadline; } //d
};
void permutacja_(int k, int n, vector<Item> M1, vector<Item> M1_wh)
{
int suma=0, diff = 0;
if(k==0)//jesli gotowa permutacja
{
int g=0, j=0;
for(int i=0; i<n; i++)//dziura
{
for(j=j+g; j<n; j++)//zadanie
{
if(M1_wh[i].Dist()==M1[j].Dist())
{
if(M1_wh[i].Index()==0)
{
suma = M1_wh[i].Time() + M1[j].Time();
M1[j+1].Time() = M1[j+1].Time() + suma;
g++;
}
else
{
suma = M1[j].Time();
M1[j+1].Time() = M1[j+1].Time() + suma;
g++;
}
}
if(M1_wh[i].Dist()>M1[j].Dist())
{
if(M1_wh[i].Index()==0)
{
suma = M1_wh[i].Time() + M1[j].Time();
M1[j+1].Time() = M1[j+1].Time() + suma;
M1_wh[i].Dist() = M1_wh[i].Dist() - M1[j].Dist();
g++;
}
else
{
suma = M1[j].Time();
M1[j+1].Time() = M1[j+1].Time() + suma;
M1_wh[i].Dist() = M1_wh[i].Dist() - M1[j].Dist();
g++;
}
for(int t=j+1; t<n; t++)//j juz jest z tym g, lecimy od kolejnego +1
{
if(M1_wh[i].Dist()>M1[t].Dist())
{
suma = M1[t].Time() + M1[t+1].Time();
M1[t+1].Time() = suma;
M1_wh[i].Dist() = M1_wh[i].Dist() - M1[j].Dist();
g++;
}
else
{
t=n;
}
}
}
if(M1_wh[i].Dist()<M1[j].Dist())
{
if(M1_wh[i].Dist() > 0)
{
if(i==0 && j==0)
{
suma = M1_wh[i].Time() + M1[j].Time() + M1_wh[i+1].Time();
M1[j+1].Time() = M1[j+1].Time() + suma;
diff = M1[j].Dist() - M1_wh[i].Dist();
M1_wh[i+1].Dist() = M1_wh[i+1].Dist() - diff;
M1_wh[i+1].Index() = 1; // dziura juz wliczona do pozycji zadania
g++;
}
else
{
suma = M1[j].Time() + M1_wh[i+1].Time();
M1[j+1].Time() = M1[j+1].Time() + suma;
diff = M1[j].Dist() - M1_wh[i].Dist();
M1_wh[i+1].Dist() = M1_wh[i+1].Dist() - diff;
M1_wh[i+1].Index() = 1;
g++;
}
}
}
}
}
}
else{
for(int i=0; i<k+1; i++)
{
Item tmp = M1[i]; //SWAP
M1[i] = M1[k];
M1[k] = tmp;
permutacja_(k-1, n, M1, M1_wh);
tmp = M1[i]; //drugi SWAP xD
M1[i] = M1[k];
M1[k] = tmp;
}
}
}
int main()
{
vector<Item> M1; // zadanka - tu leca permutacje
vector<Item> M1_wh; //tutaj same dziury
vector<Item> M2; // druga maszyna zalezy od dziur i permutacji zadan na pierwszej
int a=0,b=0,c=0,d=0,n=0, k=0;
int x=0,y=0,z=0,v=0, T=0;
//Item suma;
//Item diff;
ifstream filee;
filee.open("zadania.txt", ios::in);
filee>>n;//tyle dziur ile zadan
k = n-1;
for(int i=0; i<n; i++)
{
filee >> a >> b >> c >> d;
M1.push_back(Item(a,b,c,d));
}
filee.close();
cout << "Czasy trwania konserwacji maja wynosic: " << endl;
cin >> x;
cout << "Okresy pomiedzy konserwacjami maja byc nie wieksze niz: " << endl;
cin >> T;
for(int i=0; i<n; i++)//czas, okres, dwa zera
{
z,v=0;
y = rand() % T + 1;
M1_wh.push_back(Item(x,y,z,v));
}
permutacja_(k, n, M1, M1_wh);
return 0;
}
Oto całość kodu. Time() zwraca wartość pola danego obiektu, analogicznie Dist() Index() i Deadline() i tu chyba jest problem. W algorytmie nie tyle ma zwracać, co wykonywać działania na polu obiektu o wskazanym indeksie w tym np. i+1 lub i-1.