解题思路:
注意事项:
参考代码:
#include <stdlib.h> #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main(){ int m = 0,n = 0; int t = 0; int wi = 0; int i; cin>>n>>m; int* w = (int*)malloc(sizeof(int)*(n+1)); for(i = 0;i < n;i++){ scanf("%d",&w[i]); } w[n] = 0; int* tap = (int*)malloc(sizeof(int)*m); memset(tap,0,sizeof(int)*m); wi = 0; int fm = 0; //ÕýÔÚ½ÓË®µÄË®ÁúÍ·¸öÊý while(w[wi] || fm ){ t++; for(i = 0;i<m;i++){ if(tap[i] == 0 && w[wi]){ fm++; tap[i] = w[wi]; w[wi] = 0; wi++; } tap[i]--; if(tap[i] == 0){ fm--; } } } printf("%d\n",t); free(tap); free(w); return 0; }
0.0分
1 人评分