编程介的小学生 2019-06-17 16:01 采纳率: 20.5%
浏览 183

模拟服务器的负载均衡实现的算法,怎么采用C语言的程序的编写的思想方法和过程来实现这一模拟的

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

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-25 19:23
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题