主观

阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。

  【说明】

 著名的四色定理指出任何平面区域均可以用4种颜色着色,使相邻区域着不同的颜色。本程序对给定的区域图找出所有可能的不超过4种颜色的着色方案。

 【函数】

 # include <stdio.h>

 #define N 10 /*要着色的N个区域*/

 void output(int color[]) /*输出一种着色方案 color[i]的值为区域i所着颜色*/

 {

   int i;

   for (i=0; i<N; i++)

     printf("%4d", color[i]);

   printf("\n");

 }

 int back(int *ip, int color[j] /*回溯*/

    int c=4;

    while (c==4)

    {

      if (*ip<=0)

        return 0:

      --(*ip);

    c=(1);

      color[*ip]=-1;

    }

    return c;

 }

 /*检查区域i,考查c种颜色的可能性 */

 int colorOK(iht i, int c, int adj[][N], int color[])

 {

   int j;

   for(j=0; j<i; j++)

     if ((2))

       return 0;

   return 1;

 }

 /*为区域i选一种可着的颜色*/

 int select(int i, int c, int adj[][N], int color[])

 /*寻找各种着色方案 adj[i][j]=1表示区域i与区域j不相邻*/

 {

   int k;

   for (k=c; k<=4; k++) /*4种颜色*/

     if (colorOK((3)))

       return k;

   return 0;

 }

 int coloring(int adj[][N])

 {

   int color[N], i, c, cnt;

   for (i=0; i<N; i++) color[i]=-1:

   i=c=0; cnt=0;

   while (1)

   [

     if ((c=(4))==0)

       {

         c=back(&i, color);

           if (c==0)

             return cnt;

        }

      else

      {

        (5);

        i++;

        if(i==N)

         {

            output(color);

            ++cnt;

            c=back(&i, color);

         }

        else

          c=0;

     }

   }

 }

 void main()

 {

   int adj[N][N]={ {0, 1, 0, 1, 1, 1, 1, 1, 1, 1},

          {1, 0, 1, 1, 0, 1, 1, 1, 1, 0},

          {0, 1, 0, 1, 0, 1, 1, 0, 1, 1},

          {1, 1, 1, 0, 1, 1, 0, 0, 1, 1},

          {1, 0, 0, 1, 0, 1, 0, 0, 0, 0},

          {1, 1, 1, 1, 1, 0, 1, 0, 0, 1},

          {1, 1, 1, 0, 0, 1, 0, 0, 1, 0},

          {1, 1, 0, 0, 0, 0, 0, 0, 1, 1},

         

参考答案
您可能感兴趣的试题

阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。

  【说明】

 本程序的功能是实现任意两个大整数的乘法运算,例如:

 输入整数1:8934793850094505800243958034985058

 输入整数2:234584950989689084095803583095820923

 二者之积:

 209596817742739508050978890737675662366433464256830959194834854876 8534

 【C++代码】

 #include<iostream.h>

 const int MAXINPUTBIT=100;

 const int MAXRESULTBIT=500;

 class LargeNumber{

   int i,j;

   int temp;

   int one[MAXINPUTBIT+1];

   int onebit;  //one的位数

   int two[MAXINPUTBIT+1];

   int twobit;       //two的位数

   int result[MAXRESULTBIT+1];

 public:

   LargeNumber();

   ~LargeNumber();

   int inputone();     //出错返叫0,否则返回1

   int inputtwo();     //同上

   void multiplication(); //乘

   void clearresult();   //清零

   void showresult();   //显示

 };

 LargeNumber∷LargeNumber()

 {

   for(i=0;i<=MAXINPUTBIT;i++)

   {

     one[i]=0;

     two[i]=0;

   }

   nebit=0;

   twobit=0;

   inputone();

   inputtwo();

 }

 LargeNumber∷~LargeNumber()

 {

 }

 int LargeNumber∷inputone()

 {

   char Number[MAXINPUTBIT+1];

   cout<<"Please enter one:";

   cin>>Number;

   i=0;

   j=MAXINPUTBIT;

   while(Number[i]!='\0')

     i++;

   nebit=i;

   for(i--;i>=0;i--,j--)

   {

     if(int(Number[i])>=48&&int(Number[i])<=57)

        (1);  //由字符转换为数字

     else

       return 0;

   }

   return 1;

 }

 int LargeNumber∷inputtwo()

 {

   char Number[MAXINPUTBIT+1];

   cout<<"Please enter two:";

   cin>>Number;

   i=0;

   j=MAXINPUTBIT;

   while(Number[i]!='\0')

     i++;

   twobit=i;

   for(i--;i>=0;i--,j--)

   {

     if(int(Number[i])>=48&&int(Number[i])<=57)

       two[j]=int(Number[i]-48);  //由字符转换为数字

     else

       return 0;

   }

   return 1;

 }

 void LargeNumber∷multiplication()  //乘法

 {

   clearresult();

   int m;

   for(i=MAXINPUTBIT;i>=0;i--)

   {

     temp=two[i];

     for(j=(2),m=MAXINPUTBIT;m>=0;m--,j--)

     {

       result[j]+=temp*one[m];

       if(result[j]>9)

       {

         result[j-1]+=result[j]/10;

          (3);

       }

     }

&n

阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。

  【说明】

 著名的四色定理指出任何平面区域均可以用4种颜色着色,使相邻区域着不同的颜色。本程序对给定的区域图找出所有可能的不超过4种颜色的着色方案。

 【函数】

 # include <stdio.h>

 #define N 10 /*要着色的N个区域*/

 void output(int color[]) /*输出一种着色方案 color[i]的值为区域i所着颜色*/

 {

   int i;

   for (i=0; i<N; i++)

     printf("%4d", color[i]);

   printf("\n");

 }

 int back(int *ip, int color[j] /*回溯*/

    int c=4;

    while (c==4)

    {

      if (*ip<=0)

        return 0:

      --(*ip);

    c=(1);

      color[*ip]=-1;

    }

    return c;

 }

 /*检查区域i,考查c种颜色的可能性 */

 int colorOK(iht i, int c, int adj[][N], int color[])

 {

   int j;

   for(j=0; j<i; j++)

     if ((2))

       return 0;

   return 1;

 }

 /*为区域i选一种可着的颜色*/

 int select(int i, int c, int adj[][N], int color[])

 /*寻找各种着色方案 adj[i][j]=1表示区域i与区域j不相邻*/

 {

   int k;

   for (k=c; k<=4; k++) /*4种颜色*/

     if (colorOK((3)))

       return k;

   return 0;

 }

 int coloring(int adj[][N])

 {

   int color[N], i, c, cnt;

   for (i=0; i<N; i++) color[i]=-1:

   i=c=0; cnt=0;

   while (1)

   [

     if ((c=(4))==0)

       {

         c=back(&i, color);

           if (c==0)

             return cnt;

        }

      else

      {

        (5);

        i++;

        if(i==N)

         {

            output(color);

            ++cnt;

            c=back(&i, color);

         }

        else

          c=0;

     }

   }

 }

 void main()

 {

   int adj[N][N]={ {0, 1, 0, 1, 1, 1, 1, 1, 1, 1},

          {1, 0, 1, 1, 0, 1, 1, 1, 1, 0},

          {0, 1, 0, 1, 0, 1, 1, 0, 1, 1},

          {1, 1, 1, 0, 1, 1, 0, 0, 1, 1},

          {1, 0, 0, 1, 0, 1, 0, 0, 0, 0},

          {1, 1, 1, 1, 1, 0, 1, 0, 0, 1},

          {1, 1, 1, 0, 0, 1, 0, 0, 1, 0},

          {1, 1, 0, 0, 0, 0, 0, 0, 1, 1},

         

¥

订单号:

遇到问题请联系在线客服

订单号:

遇到问题请联系在线客服