hdu 2850 Load Balancing (优先队列 + 贪心)
题目大意:
怎么分配n个任务到m个server上使得负载尽量平衡。
思路:
将任务从大到小排序,依次放入负载最小的那个server中。
由于是spj 的缘故,所以能够使用这个贪心。
比方数据
6 2
7 5 3 3 3 3
就会得到错误答案。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std; struct node
{
int index,load;
bool operator < (const node &cmp)const
{
return load>cmp.load;
}
};
struct foo
{
int index,v;
bool operator < (const foo &cmp)const
{
return v<cmp.v;
}
}save[100005];
priority_queue <node> Q;
int n,m;
int ans[100005];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(ans,0,sizeof ans);
while(!Q.empty())Q.pop(); scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
save[i].index=i;
scanf("%d",&save[i].v);
} sort(save+1,save+1+n); for(int i=0;i<m;i++)
{
node t;
t.index=i;
t.load=0;
Q.push(t);
} for(int i=n;i>=1;i--)
{
node t=Q.top();
Q.pop(); t.load+=save[i].v;
// printf("---%d\n",t.load);
ans[save[i].index]=t.index; Q.push(t);
}
printf("%d\n",n);
for(int i=1;i<=n;i++)
{
printf("%d%c",ans[i],i==n?'\n':' ');
}
}
return 0;
}
hdu 2850 Load Balancing (优先队列 + 贪心)的更多相关文章
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- 【架构】How To Use HAProxy to Set Up MySQL Load Balancing
How To Use HAProxy to Set Up MySQL Load Balancing Dec 2, 2013 MySQL, Scaling, Server Optimization U ...
- CF# Educational Codeforces Round 3 C. Load Balancing
C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- UVA 12904 Load Balancing 暴力
Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...
- Load Balancing 折半枚举大法好啊
Load Balancing 给出每个学生的学分. 将学生按学分分成四组,使得sigma (sumi-n/4)最小. 算法: 折半枚举 #include <iostrea ...
- [zz] pgpool-II load balancing from FAQ
It seems my pgpool-II does not do load balancing. Why? First of all, pgpool-II' load balancing is &q ...
- How Network Load Balancing Technology Works--reference
http://technet.microsoft.com/en-us/library/cc756878(v=ws.10).aspx In this section Network Load Balan ...
- Network Load Balancing Technical Overview--reference
http://technet.microsoft.com/en-us/library/bb742455.aspx Abstract Network Load Balancing, a clusteri ...
- How Node.js Multiprocess Load Balancing Works
As of version 0.6.0 of node, load multiple process load balancing is available for node. The concept ...
随机推荐
- js返回当前时间的毫秒数
Date.now(); +new Date(); new Date().getTime();
- GetLastError来获得错误信息转成文本描述
我们一般在调用了一些API后都会用GetLastError来获得错误信息,但是信息都是Integer的,我们知道是什么意思么?嘿嘿,是的,有msdn呀,当然还可以用FormatMessage函数来.正 ...
- delphi 打开文件夹并定位到一个文件(使用ShellExecute时加一个select参数,原来这么简单!)
strFileName := FcxLV[nIndex].Items.Item[FcxLV[nIndex].ItemIndex].SubItems.Strings[0]; //路径 ShellExe ...
- CC++初学者编程教程(4) 安装Oracle12c于Windows Sever2012
我们开启虚拟机 Windows Sever2012启动中. 3.看到WindowsSever2012的桌面. 我们解压缩两个文件, winx64_12c_database_1of2.zip,winx6 ...
- Java调用.dll文件
因为项目的需求,要在JAVA项目中调用Windows的Dll(动态链接库)文件,之前用Jni调用过C写的Dll文件,比较麻烦,这里不多说,网上也有很多这方面的文档.在网上找到一个开源的组件JNativ ...
- 利用margin代替小图标的绝对定位;使代码更简洁
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0。
题目:任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0. 解法一:暴力求解.从1开始查找M,然后判断M*N=X这个数字是否只含有0,1. 解法二:由 ...
- asp-net-web-api 自定义URl插件
http://attributerouting.net/#asp-net-web-api https://github.com/johnpapa/CodeCamper/blob/master/Code ...
- jQuery插件autoComplete使用详解
安装/需要引入的文件 <script type="text/javascript" src="../js/jquery-1.8.3.min.js.js"& ...
- 项目从Codeigniter 2.2升级至 Codeigniter 3.0的一些注意事项
1. 替换掉system目录下所有的文件和文件夹,以及替换掉index.php 2. controllers和models中的文件首字母都需要改成大写:application.php -> Ap ...