Nhờ các bác xét giùm bài này có sai sót và thiếu sót gi ko? void main viết như thế nào? Thanks
#include <iostream.h>
//khai bao bien toan cuc
int n; //so dinh, n<=30
int R[30][30]; // do thi ban do
int m=0; //so mau duoc dung
int d[30]; //so dinh canh dinh i ma chua duoc to mau
int fa[30]; //fuong an To mau cua 30 dinh
char * mau(int m)
{
switch (m)
{
case 1: return "Xanh";
case 2: return "Do";
case 3: return "Tim";
case 4: return "Vang";
}
}
void nhap()
{ int i,j;
n=5;
//nhap bai toan vao ma tran R
for (i=0;i<n; i++)
for(j=0; j<n; j++)
R[j]=0;
//nhap
R[0][1]=R[1][0]=R[2][1]=R[1][2]=R[1][4]=R[4][1]=R[2][3]=R[3][2]=R[2][4]=R[4][2]=R[3][4]=R[4][3]=1;
R[0][2]=R[2][0]=R[0][3]=R[3][0]=1;
R[0][4]=R[4][0]=1;
}
int timDinhCaoNhat(int d[], int n)
{
int dinh=-2, sodinhke=-1;
for(int i=0; i<n; i++)
if(d>sodinhke)
{
dinh=i;
sodinhke=d;
}
return dinh;
}
void timFAtomau()
{
//so FAtomau dau tien =0;
m=0;
int i=0, j=0;
int DinhCaoNhat;
int mauchon=1;
//cap nhat d
for (i=0; i<n; i++)
{
d=0;
for(j=0; j<n; j++)
if (R[j]==1)
d++;
cout<<d<<endl;
}
//fuong an to mau cua n dinh deu =0(chua to)
for(i=0; i<n; i++)
fa=0;
//vonglapchinh
for(i=0;i<n;i++)
{ ////
//PHAN 1
DinhCaoNhat=timDinhCaoNhat(d, n); //neu khong co thi tra ve-2
cout<<"Dinh cao nhat"<<DinhCaoNhat<<endl;
if (DinhCaoNhat!=-2)
{
d[DinhCaoNhat]=-1; //danh dau -1 tuc la da To mau, khong chon lai nua
mauchon=1;
//XET CAC DINH CANH NO
for(j=0; j<n; j++)
if(DinhCaoNhat!=j && R[DinhCaoNhat][j]==1 )
{ if (d[j]>-1)
d[j]--; //giam bac cac dinh canh no chua to
cout<<"giam bac d[ "<<j<<" ] thanh "<<d[j]<<endl ;
if(fa[j]==mauchon) //XEM CO BI TRUNG MAU CANH KHONG
{
mauchon++; //NEU CO THI TANG MAUCHON LEN
}
}
//TO MAU CHO DINH CAO NHAT
fa[DinhCaoNhat]=mauchon;
}
}
#include <iostream.h>
//khai bao bien toan cuc
int n; //so dinh, n<=30
int R[30][30]; // do thi ban do
int m=0; //so mau duoc dung
int d[30]; //so dinh canh dinh i ma chua duoc to mau
int fa[30]; //fuong an To mau cua 30 dinh
char * mau(int m)
{
switch (m)
{
case 1: return "Xanh";
case 2: return "Do";
case 3: return "Tim";
case 4: return "Vang";
}
}
void nhap()
{ int i,j;
n=5;
//nhap bai toan vao ma tran R
for (i=0;i<n; i++)
for(j=0; j<n; j++)
R[j]=0;
//nhap
R[0][1]=R[1][0]=R[2][1]=R[1][2]=R[1][4]=R[4][1]=R[2][3]=R[3][2]=R[2][4]=R[4][2]=R[3][4]=R[4][3]=1;
R[0][2]=R[2][0]=R[0][3]=R[3][0]=1;
R[0][4]=R[4][0]=1;
}
int timDinhCaoNhat(int d[], int n)
{
int dinh=-2, sodinhke=-1;
for(int i=0; i<n; i++)
if(d>sodinhke)
{
dinh=i;
sodinhke=d;
}
return dinh;
}
void timFAtomau()
{
//so FAtomau dau tien =0;
m=0;
int i=0, j=0;
int DinhCaoNhat;
int mauchon=1;
//cap nhat d
for (i=0; i<n; i++)
{
d=0;
for(j=0; j<n; j++)
if (R[j]==1)
d++;
cout<<d<<endl;
}
//fuong an to mau cua n dinh deu =0(chua to)
for(i=0; i<n; i++)
fa=0;
//vonglapchinh
for(i=0;i<n;i++)
{ ////
//PHAN 1
DinhCaoNhat=timDinhCaoNhat(d, n); //neu khong co thi tra ve-2
cout<<"Dinh cao nhat"<<DinhCaoNhat<<endl;
if (DinhCaoNhat!=-2)
{
d[DinhCaoNhat]=-1; //danh dau -1 tuc la da To mau, khong chon lai nua
mauchon=1;
//XET CAC DINH CANH NO
for(j=0; j<n; j++)
if(DinhCaoNhat!=j && R[DinhCaoNhat][j]==1 )
{ if (d[j]>-1)
d[j]--; //giam bac cac dinh canh no chua to
cout<<"giam bac d[ "<<j<<" ] thanh "<<d[j]<<endl ;
if(fa[j]==mauchon) //XEM CO BI TRUNG MAU CANH KHONG
{
mauchon++; //NEU CO THI TANG MAUCHON LEN
}
}
//TO MAU CHO DINH CAO NHAT
fa[DinhCaoNhat]=mauchon;
}
}