文档介绍:该【算法设计与分析-第二版-吕国英---第四章课后习题答案 】是由【青山代下】上传分享,文档一共【9】页,该文档可以免费在线阅读,需要了解更多关于【算法设计与分析-第二版-吕国英---第四章课后习题答案 】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文字是截取该文章内的部分文字,如需要获得完整电子版,请下载此文档到您的设备,方便您编辑和打印。:..#include<>#include<>voidmain(){inti,n,sum=0,power,proce,remainder,interger,decimal;printf(〞请输入2+22+…+2222(n个2)(不考虑精度)的for(i=1;i<=n&&i<=9;i++)proce=(int)(pow(10,i)-1)/9*2;{sum=sum+proce;}if(n>9){for(i=1,power=n-9;i<=power;i++)proce=(int)(pow(10,9)-1)/9*2;{sum=sum/10+proce;remainder=sum%10;if(remainder>=5)sum++;}interger=sum/100000000;decimal=sum%100000000;…+2222(n个2)(不考虑精度)}else…+2222(n个2)(不考虑精度}#include<>voidmain(){inti,total=2,day=10;for(i=day-1;i>=1;i--)total=(total+2)*2;第一天共有%d个桃。:..#include<>voidmain(){共有牌:%d张电脑出:while(last>1){还有牌:%d张您出:电脑出:}还有牌:%d张。您只能输入1。您出:您输了……}#include<>voidmain(){intarray[8][8],i,j,i1=0,i2=1,i3=2,i4=3,i5=4,i6=5,i7=6,i8=7,j1=0,j2=0,j3=0,j4=0,j5=0,j6=0,j7=0,j8=0;//先判断不在同一行和同一列,然后再做不在对角线此处预先规定,第一行第一列处是皇后。for(j2=1;j2<8;j2++)for(j3=1;j3<8;j3++)for(j4=1;j4<8;j4++)for(j5=1;j5<8;j5++)for(j6=1;j6<8;j6++)for(j7=1;j7<8;j7++)for(j8=1;j8<8;j8++)if(j3!=j2)if(j4!=j2&&j4!=j3)if(j5!=j2&&j5!=j3&&j5!=j4)if(j6!=j2&&j6!=j3&&j6!=j4&&j6!=j5)if(j7!=j2&&j7!=j3&&j7!=j4&&j7!=j5&&j7!=j6)if(j8!=j2&&j8!=j3&&j8!=j4&&j8!=j5&&j8!=j6&&j8!=j7):..if((i2-i1+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(j=0;j<8;j++)array[i][j]=0;:..array[i1][j1]=1;array[i2][j2]=1;array[i3][j3]=1;array[i4][j4]=1;array[i5][j5]=1;array[i6][j6]=1;array[i7][j7]=1;array[i8][j8]=1;是皇后所在位置,0为其它位置。for(i=0;i<8;i++)for(j=0;j<8;j++):..#include<>voidmain(){intgoods=100,big=0,middle=0,small=0;for(big=0;big<=33;big++)for(middle=0;middle<=50;middle++)for(small=0;small<=100;small=small+2)if((big+middle+small)==100)if((big*3+middle*2+small/2)==goods)大马:%2d中马:%2d小马}#include<>voidmain(){intn,flag=1;for(n=7;flag;n=n+7)if(n%2==1)if(n%3==2)if(n%5==4)if(n%6==5)flag=0;该数为}#include<>voidmain(){:..intth,flag=0;for(th=1000;th<9999;th++)if(th/1000!=th/100%10)if(th/1000!=th/10%10)if(th/1000!=th%10)if(th/100%10!=th/10%10)if(th/100%10!=th%10)if(th/10%10!=th%10)if(th%((th/1000)*(th/1000))==0){flag=0;if((th/100%10)==0)flag=1;elseif(th%((th/100%10)*(th/100%10))==0)flag=1;if(flag==1){flag=0;if((th/10%10)==0)flag=1;elseif(th%((th/10%10)*(th/10%10))==0)flag=1;if(flag==1){flag=0;if(th%10==0)flag=1;elseif(th%((th%10)*(th%10))==0)flag=1;if(flag==1)}}:..#include<>main(){inta[10]={1,10,5,4,9,3,8,6,7,2};inti,max1=0,max2=0,min1=0,min2=0;for(i=0;i<10;i++){if(a[max1]<a[i])max1=i;if(a[min1]>a[i])min1=i;if(max1==0)}max2=1;if(min1==0)min2=1;for(i=0;i<10;i++){if(i==max1||i==min1)continue;if(a[max2]<a[i])max2=i;if(a[min2]>a[i])min2=i;}}#include<>intfun(intN,intbasic,intarray[]){intn1=0,n2=0,n3=0,i;n3=(N%2!=0)?N+basic:0;for(i=0;i<N/2;i++){n1+=array[basic+i+1];n2+=array[basic+N/2+i+1];}if(N==2)returnn1>n2?basic+1:basic+2;elseif(n1==n2)returnn3;elseif(n1>n2)returnfun(N/2,basic,array);elsereturnfun(N/2,basic+N/2,array);}voidmain():..{intarr[19]={0,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1};不合格品为第%d块。}