1、M; %记录S后代中各种类型的比率 while M(3,1) 2) k = k + 1; end endfprintf( the rate is %dn, k/n);3) 结果输出Please input the scale of the samples100the rate is 5.900000e-0011000the rate is 6.170000e-00110000the rate is 5.938000e-001100000the rate is 5.994300e-0011000000the rate is 5.998900e-0013. 流水问题上液面水失去的体积等于小孔流出的
2、体积,对其两边微分,求出微分方程。描点显示液面高度的变化情况。h = 8; %初始水面高度hh = 8; %记录水面高度的数组dt = 5; %时间间隔t0 = 0;tt = 0; %记录时间间隔的数组while(h 0.001) A = pi*(8 + h)*(8 + h)/64; dh = -0.001*sqrt(2*9.8*h)/A*dt; h = h + dh; hh = hh, h; t0 = t0 + dt; tt = tt, t0;hhfprintf(经过%d秒之后,容其中的水全部流出n,t0);经过7445秒之后,容其中的水全部流出4. 立方体问题i. 递归生成十三个0与十四个
3、1的全排列。ii. 将每种排列从一维数组转为三维数组。iii. 分别判定每一种数组的条数iv. 比较出最小值v. 根据最小值搜索所有的情况#includeint min = 49; /记录最小的边数int count = 0; /记录符合条件的方法的个数void reshape(int D127, int D3333) /将一维数组转化为三维数组 int i,j,k; int x = 0; for(i = 0; i 3; i+) for(j = 0; j j+) for(k = 0; k k+) D3ijk = D1x; x +; void print3d(int d3333) /打印三维数组
4、 printf(第1层 第2层 第3层n for(k = 0; for(j = 0; printf(%d , d3ijk); printf( printf(n int judge(int a333) /判断 int i,j,sum; sum = 0; if(aij0 = aij1 & aij1 = aij2) sum+; /9条竖线的判断 if(ai0j = ai1j & ai1j = ai2j) sum+;/9条左右方向的横线的判断 if(a0ij = a1ij & a1ij = a2ij) sum+;/9条前后方向的横线的判断 if(ai00 = ai11 & ai11 = ai22) s
5、um+;/3条左低右高的正面的面对角线 if(a0i0 = a1i1 & a1i1 = a2i2) sum+;/3条左高右低的侧面的面对角线 if(a00i = a11i & a11i = a22i) sum+;/3条左高右低的上面的面对角线 if(ai20 = ai11 & ai11 = ai02) sum+; if(a2i0 = a1i1 & a1i1 = a0i2) sum+; if(a20i = a11i & a11i = a02i) sum+; if(a000 = a111 & a111 = a222) sum+; /4条体对角线 if(a200 = a111 & a111 = a0
6、22) sum+; if(a020 = a111 & a111 = a202) sum+; if(a220 = a111 & a111 = a002) sum+; return sum;void compare(int t) /比较 if(t min) min = t;void cube_permutation(int n, int *P, int *A, int cur) /递归生成全部不同的排列 int i, j; if(cur = n) int s333; reshape(A,s); compare(judge(s); if(judge(s) = 4) count+;第%d种情况n,co
7、unt); print3d(s); else for(i = 0;i n; if(!i|Pi != Pi-1) int c1 = 0, c2 = 0; cur; j+) if(Aj = Pi) c1+; j+) if(Pi = Pj) c2+; if(c1 0.5) if (abs(a1 - a2) = 3|abs(a2 - a3) = 3) s = s + 1;there are %d kinds of keys(3 teeth)n,s); for j4 = 1 :a4 = j4; amax = max(a1, a2, a3, a4 amin = min(a1, a2, a3, a4 num
8、bers = (amax - a1)*(a1 - amin)+(amax - a2)*(a2 - amin)+(amax - a3)*(a3 - amin)+(amax - a4)*(a4 - amin); if (abs(a1 - a2) = 3|abs(a2 - a3) = 3|abs(a3 - a4) = 3)there are %d kinds of keys(4 teeth)n for j5 = 1 :a5 = j5; amax = max(a1, a2, a3, a4, a5 amin = min(a1, a2, a3, a4, a5 numbers = (amax - a1)*(
9、a1 - amin)+(amax - a2)*(a2 - amin)+(amax - a3)*(a3 - amin)+(amax - a4)*(a4 - amin)+(amax - a5)*(a5 - amin); if (abs(a1 - a2) = 3|abs(a2 - a3) = 3|abs(a3 - a4) = 3|abs(a4 - a5) = 3)there are %d kinds of keys(5 teeth)n for j6 = 1 :a6 = j6; amax = max(a1, a2, a3, a4, a5, a6 amin = min(a1, a2, a3, a4, a
10、5, a6 numbers = (amax - a1)*(a1 - amin)+(amax - a2)*(a2 - amin)+(amax - a3)*(a3 - amin)+(amax - a4)*(a4 - amin)+(amax - a5)*(a5 - amin)+(amax - a6)*(a6 - amin); if (abs(a1 - a2) = 3|abs(a2 - a3) = 3|abs(a3 - a4) = 3|abs(a4 - a5) = 3|abs(a5 - a6) = 3)there are %d kinds of keys(6 teeth)n for j7 = 1 : end there are %d kinds of keys(7 teeth)nthere are %d kinds of keys(8 teeth)nthere are 8 kinds of keys(3 teeth)there are 64 kinds of keys(4 teeth)there are 360 kinds of keys(5 teeth)there are 1776 kinds of keys(6 teeth)there are 7104 kinds of keys(7 teeth)there are 28416 kinds of keys(8 teeth)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1