Multi-machine scheduling problem (greedy)

Algorithm design example: multi-machine scheduling problem (greedy)

memory limit: 32768KB time limit: 1000MS

accept: 9 submit: 19

Description

There are n independent jobs {1, 2, ..., n}, which are processed by m identical machines. The processing time required for job i is ti. It is now agreed that each job can be processed on any machine, but processing is not allowed to be interrupted before completion. A job cannot be split into smaller subjobs.
Now it is required to give a job scheduling scheme, so that the given n jobs can be processed and processed by m machines in the shortest possible time.
Input

The first input is the number of test samples T ( T <= 100 ), followed by T test samples. The first line of each test case is two integers n and m ( n < 1000, m < 1000 ), followed by n lines, each with an integer representing the processing time required for the ith job

Output

One line is output for each test case, in the format "Case #: t", where '#' indicates the number of test cases (counting from 1), and t indicates the shortest time required to complete all tasks.

Sample Input

1
7 3
2
14
4
16
6
5
3
Sample Output

Case 1: 17
It is said that it was not found in ZAUOJ

Parse

Priority is given to the machine with the shortest running time.

AC code

#include<iostream>
#include<cstdio>

#include<cstring>
#include<bitset>
#include<sstream>
#include<string.h>
#include<iomanip>

#include<cmath>
#include<algorithm>
#include<cstdlib>

#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long 
const ll inf=0x3f3f3f3f;
typedef pair<int ,int > PII;
int cmp(int a,int b){
    
    
	return a>b;
}
int arr[1005],cost[1005];
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int n,m;
		cin>>n>>m;
		for(int i=0;i<n;i++)
		cin>>arr[i];
		sort(arr,arr+n,cmp);//时间长到低排序
		for(int i=0;i<n;i++){
    
    
			*min_element(cost,cost+m)+=arr[i];
		}
		cout<<*max_element(cost,cost+m)<<endl;
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325812290&siteId=291194637