其他分享
首页 > 其他分享> > duoji_diaodu

duoji_diaodu

作者:互联网

#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int casenum;
int tab[1003];
int machine[1002];
bool compare(int a,int b){
    if(a>b) return true;
    else return false;
}
int main (){
    scanf("%d",&casenum);
    for(int k=1;k<=casenum;++k){
        int zuoyenum,machinenum;
        scanf("%d%d",&zuoyenum,&machinenum);
        for(int i=1;i<=zuoyenum;++i){
            scanf("%d",&tab[i]);
        }
        sort(tab+1,tab+1+zuoyenum,compare);
      /*  for(int i=1;i<=zuoyenum;++i){
            printf("%d ",tab[i]);
        }*/
       //int zuobian=0;
       //int zuixiaozhi=0;
        memset(machine,0,sizeof(machine));
     /*   for(int i=1;i<=machinenum;++i){
            machine[i]=tab[i];
        }
        least_to_jieshu=machinenum;*/ //错误,如果作业的数量少于机器的数量,那么,这个就成立。
        for(int i=1;i<=zuoyenum;++i){
                 int zuobiao=0;
                int zuixiaozhi=99999999;//这个值要赋值为1,因为赋值为0,就会无法选出最早结束的机器时间
            for(int j=1;j<=machinenum;++j){
                if(machine[j]<zuixiaozhi){
                    zuixiaozhi=machine[j];
                    zuobiao=j;
                }
            }
            //printf("最早结束的机器代号为 %d\n",zuobiao);
            machine[zuobiao]= machine[zuobiao]+tab[i];
         /*  for(int j=1;j<=machinenum;++j){
               printf("第%d台机器,完成工作结束时间%d\n",j,machine[j]);
            }
*/
        }

                int zuixiaozhi=0;
        for(int j=1;j<=machinenum;++j){
                if(machine[j]>zuixiaozhi){
                    zuixiaozhi=machine[j];

                }
        }
        printf("Case %d: %d\n",k,zuixiaozhi);
    }
}

标签:return,int,machine,diaodu,casenum,zuixiaozhi,include,duoji
来源: https://www.cnblogs.com/waibizi/p/12070150.html