求解钢材切割的最佳订单.docx

上传人:scccc 文档编号:12784833 上传时间:2021-12-06 格式:DOCX 页数:7 大小:17.14KB
返回 下载 相关 举报
求解钢材切割的最佳订单.docx_第1页
第1页 / 共7页
求解钢材切割的最佳订单.docx_第2页
第2页 / 共7页
求解钢材切割的最佳订单.docx_第3页
第3页 / 共7页
求解钢材切割的最佳订单.docx_第4页
第4页 / 共7页
求解钢材切割的最佳订单.docx_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《求解钢材切割的最佳订单.docx》由会员分享,可在线阅读,更多相关《求解钢材切割的最佳订单.docx(7页珍藏版)》请在三一文库上搜索。

1、本题为第五届全国ITAT教育工程就业技能大赛决赛试题C语言程序设计第一题题目描述1、求解钢材切割的最佳订单。(60分)(1 )描述:编写程序,从订单中选择一组订单对钢材作切割加工,使钢材得到最佳利用,约定每一次切割 会损耗固定长度的钢材(约定该值为 2)。已知线型钢材总长度、订单数和各订单需要的钢材长度;(2) 输入:钢材总长度s、订单数n、各定单需要的钢材长度;(3)输岀:可以使钢材得到最佳利用的订单号、该订单需要的钢材长度。例如:n :8 (回车)Please input total length of the steel s:28 (回车)Please input number of o

2、rderPlease input the orders :5 (回车)6 (回车)7 (回车)8 (回车)9 (回车)10 (回车)12 (回车)15 (回车)屏幕输出:1Choice one order 1 length=5order 3 length=7order 7 length=12Choice two order 2 length=6order 4 length=8order 6 length=10printf("订单号是:%d,长度为:%d"小,p n);Press any key to quit代码如下#i nclude <malloc.h>#i

3、nclude <stdio.h>int *p, *pt;int gle n,dnu m, i,sum=0,n,num=0;int nlen=0;测试函数void test( int start,i nt en d,i nt gle n) / int nu二 0,le n=0,n, m,i;ptstart=1; 选中for(i=0;i<=e nd;i+)if(pti)len+=pti*pi;nu+;/求选中的总长if(le n+( nu -2)*2=gle n)for(n=1; n<二end;n+)if(pt n)7nlen+;prin tf("nn"

4、);输出if(le n+( nu-2)*2<gle n)for(m=start+1;m<=e nd;m+)test(m,end,glen);对下一个元素测试ptstart=O; 恢复int mai n()printf("请输入钢材长度和订单数量n");sca nf("%d%d", &gle n,&dnu m);p = ( int * )malloc( (dnu m+1)*sizeof( int);pt = ( int * )malloc( (dnu m+1)*sizeof( int);if ( (p二二NULL) | (pt二

5、二NULL)printf("内存不足,分配失败n");return 0;p0=0;for(i=1; i<=dnum; i+) / 输入订单需求printf("第%d个订单需要钢材的长度",i);sea nf("%d",&pi);for(i=0; i<=d nu m+1; i+)pti=0;/*对于函数调用中,首先将每一个元素置1,选中,再递归,置0,恢复。但对于第一个元素不是这样的,只有选中的情况,没有置0的情况,当第一个元素为0时,第一层递归也就结束了,所以我第一个元素是不用 的(只置1),从第二个开始,也就是下标为1的元素。所以申请n+1个*/void test( int start,i nt en d,i nt gle n);test(0,d nu m,gle n);printf("nn 共有 %d 种方案 n",nlen);return 0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1