多校第十场——1011 Task Scheduler

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;
			}
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>