软考常用算法设计方法(一)(6)
# include # include typedef struct ele {
软考常用算法设计方法(一)(6)
# include # include typedef struct ele { int vno; struct ele *link; } ele; typedef struct hnode { int remainder; ele *head; struct hnode *next; } hnode; void main() { int n, i, box_count, box_volume, *a; hnode *box_h, *box_t, *j; ele *p, *q; printf(“输入箱子容积\n”); scanf(“%d”,&box_volume); printf(“输入物品种数\n”); scanf(“%d”,&n); a=(int *)malloc(sizeof(int)*n); printf(“请按体积从大到小依次输入各物品的体积:”); for (i=0;i box_h=box_t=null; box_count=0; for (i=0;i { p=(ele *)malloc(sizeof(ele)); p->vno=i; for (j=box_h;j!=null;j=j->next) if (j->remainder>=a[i]) break; if (j==null) { j=(hnode *)malloc(sizeof(hnode)); j->remainder=box_volume-a[i]; j->head=null; if (box_h==null) box_h=box_t=j; else box_t=boix_t->next=j; j->next=null; box_count++; } else j->remainder-=a[i]; for (q=j->next;q!=null&&q->link!=null;q=q->link); if (q==null) { p->link=j->head; j->head=p; } else
软考常用算法设计方法(一)(6) 来自淘豆网m.daumloan.com转载请标明出处.