Problem Description
ByteCompany has a server cluster with m workers, k of which are somehow disconnected.
The task scheduler have just received n tasks, and the i-th task needs to be executed on ti workers.
For an executive order of p1,p2,…pn, the task scheduler will assign workers for them respectively. Specifically, for the i-th task pi, the scheduler will select tpi workers randomly from all workers which hasn’t been assigned tasks at this moment. Each of those free workers share a universal equal probability to be selected. Note that disconnected workers may also be selected. In this scenario, the current scheduling will be considered as a failure and retry automatically and immediately. Only when the scheduling of the current task is successful, the next task will be proceeded.
Now you need to find an optimal executive order of p1,p2,…pn to minimize the expected amount of the scheduling process. We guarantee that the amount of connected workers is enough to finish all scheduling.
Input
The input contains several test cases, and the first line contains a single integer T (1≤T≤100), the number of test cases.
For each test case, the first line contains three integers n (1≤n≤100), m (n≤m≤10000) and k (0≤k≤m−n): the number of tasks, the total number of workers and the number of disconnected workers.
The following line contains n positive integers t1,t2,t3,…,tn (n≤∑ni=1ti≤m−k), describing the number of needed worker for each task.
Output
For each test case, output n integers p1,p2,…,pn on a single line representing the order of tasks to be scheduled.
If there are multiple solutions, output the lexicographically smallest one.
Sample Input
2
2 4 1
1 2
3 3 0
1 1 1
Sample Output
2 1
1 2 3
题意:
有n个任务,m个工作者,存在k个人不在,第i个任务需要ti个工作者,被选的概率相同,选到不在的工作者则重选,求出分配次数期望值最小的分配方法。
思路:
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 20;
const ll mod = 1000000007;
struct node
{
int k, w;
} nodes[N];
bool cmp(node a, node b)
{
if (a.w == b.w)
return a.k < b.k;
return a.w > b.w;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t, m, k, n;
cin >> t;
while (t--)
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
cin >> nodes[i].w, nodes[i].k = i;
if (!k)
{
for (int i = 1; i <= n; i++)
{
if (i != n)
cout << i << ' ';
else
cout << i << endl;
}
}
else
{
sort(nodes + 1, nodes + 1 + n, cmp);
for (int i = 1; i <= n; i++)
{
if (i != n)
cout << nodes[i].k << ' ';
else
cout << nodes[i].k << endl;
}
}
}
}