#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 101;
struct node
{
int val;
int id;
};
bool cmp(node a, node b)
{
return a.val > b.val;
}
int main()
{
node a[N], b[N];
int vis[N];
int n, m;
cout << "the number of the work" << endl;
cin >> n;
cout << "the time the i's work need" << endl;
for (int i = 0; i < n; i++)
{
cin >> a[i].val;
a[i].id = i;
}
cout << "the number of machines" << endl;
cin >> m;
cout << "the time of the ith machinie can work" << endl;
for (int i = 0; i < m; i++)
{
cin >> b[i].val;
b[i].id = i;
}
for (int i = 0; i < n; i++)
vis[i] = -1;
sort(a, a + n, cmp);
sort(b, b + m, cmp);
/*for (int i = 0; i < m; i++)
cout << b[i] << " ";
cout << endl;
for (int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;*/
for (int i =0;i<m;i++)
{
for (int j = 0; j < n; j++)
{
if (b[i].val >= a[j].val && vis[a[j].id] == -1)
{
b[i].val -= a[j].val;
vis[a[j].id] = b[i].id;
cout << b[i].val << endl;
}
}
}
for (int i = 0; i < n; i++)
{
if (vis[i] == -1) cout << "work"<<i<<"cant solve" << endl;
else cout << "work" << i << "solved by machine" << vis[i] << endl;
}
system("pause");
return 0;
}
/*
5
7 2 4 5 3
3
8 9 6
*/
机器调度问题,请不吝赐教
最新推荐文章于 2023-10-19 21:38:44 发布