编程介的小学生 2017-06-01 06:27 采纳率: 20.5%
浏览 804
已采纳

Load Balancing

Problem Description
In the Wide Web World, Which web server was popular in web site? Apache, nginx, lighttpd? Baidu.com use Apache, and many web sites like 163.com use nginx. Why? Its configuration is very simple, and it has very powerful load balancing features.

How does load balancing work? Load balancing is a technique to spread work between two or more computers in order to get optimal resource utilization, maximize throughput, and minimize response time. Wiskey very curious about this technology and he wants to build a simple load balancing model.

He define the web site has M servers, and N jobs need be done. Each job has a processing time T; we seek to assign each job to one of the servers so that the loads placed on all servers are as "balanced" as possible. The "balanced" mean the Minimize it (max {TMi} - min {TMj}). TMi is the server i total time cost.

But, as Wiskey Know, this scheduling problem of finding an assignment of minimum gap is NP-hard.

Can you write a better load balancing than Wiskey? Challenge it~!

Input
The first integer C represents the number of cases, And C cases followed.

Each test case contains a single integer N (1<=N<=100000) and M (1<=M<=100). The next N line contains integers, meaning the time of job T1, T2Tn. (1<=Ti<=1000000)

Output
For each test case, first output the N, and follows N numbers mean the job i assign to which server. The servers number count from 0.

Sample Input
2
6 3
2 3 4 6 2 2
6 3
6 4 3 2 2 2

Sample Output
6
0 1 2 0 1 2
6
0 1 1 2 2 2

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-06-04 17:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?