?? siranse.c
字號:
#include<iostream.h>
#define MAXSIZE 10
void main(){
void mapcolor(int (*r)[MAXSIZE],int *s,int n);
int b[MAXSIZE];
int a[MAXSIZE][MAXSIZE];
int i,j,n;
int k=0,color=1;
bool zhen=true;
bool zhen1=true;
bool zhen2=true;
for(i=0;i<MAXSIZE;i++)
for(j=0;j<MAXSIZE;j++)
a[i][j]=0;
cout<<"請輸入要顏色的區域數目"<<endl;
cin>>n;
cout<<"請輸入各區域間的關系,相鄰輸入1,不相鄰輸入0"<<endl;
for(i=0;i<n;i++){
cout<<"請輸入第"<<i+1<<"行數據"<<" "<<"請輸入"<<i+1<<"個數據"<<endl;
for(j=0;j<=i;j++){
cin>>a[i][j];
a[j][i]=a[i][j];
}
}
for(j=0;j<n;j++){
b[j]=0;
}
mapcolor(a,b,n);
}
void mapcolor(int (*r)[MAXSIZE],int *s,int n){
int color ,area,k;
bool zhen=true;
s[0]=1;
area=1;
color=1;
while(area<n){
while((color<=4)&&(zhen)){//while start
k=0;
while((k<area)&&(s[k]*r[area][k]!=color)){
k++;
}
if(k<area){
color++;
}
else{
s[area]=color;
area++;
color=1;
if(area==n){
zhen=false;
}
}
}//while end
if(color>4){
area-=1;
color=s[area]+1;
}
}
cout<<"各區域染色情況如下"<<endl;
for(k=0;k<n;k++)
cout<<"區域 "<<k+1<<": "<<s[k]<<"色"<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -