CHỌN VIỆC
/*Sap xep thoi gian giam dan
chon viec:chon viec chua phan cong co thoi gian nho nhat
chon may:chon may Min*/
#include
using namespace std;
int soviec;
int somay;
int gio[100];
int ID[100];
int machine[100];
int kq[100];//cong viec j do may kq[j] thuc hien
void docfile()
{
FILE*f;
f=fopen("D:\\AI1.txt","r");
fscanf(f,"%d",&somay);
fscanf(f,"%d",&soviec);
for(int i=0;i fscanf(f,"%d",&gio[i]);
}
void init()
{
for(int i=0;i ID[i]=i;
for(int i=0;i machine[i]=0;
}
void swap(int &a,int &b)
{
int c=a;
a=b;
b=c;
}
void sapxep()
{
for(int i=0;i {
for(int j=i;j {
if(gio[i] {
swap(gio[i],gio[j]);
swap(ID[i],ID[j]);
}
}
}
}
int chonmay()
{
int min=machine[0];
int n=0;
for(int i=1;i if(machine[i] {
min=machine[i];
n=i;
}
return n;
}
void xuly()
{
sapxep();
for(int i=0;i {
int k=chonmay();
machine[k]+=gio[i];
kq[ID[i]]=k;//cong viec ID[i] do may k thuc hien
}
}
void xuat()
{
for(int i=0;i cout<<"\n Cong viec "<}
void main()
{
docfile();
init();
xuly();
xuat();
system("pause");
}