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 ...
随机推荐
- AIX 命令大全
http://www.ahinc.com/aix/general.htm http://web.mit.edu/javadev/packages/Acme/ http://jparsec.codeha ...
- 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页
itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...
- poj1338
Ugly Numbers Time Limit ...
- oracle check if the display variable is set
- aix archPlat
#++++++++++++++++++++++++++++++++++++++++++++++++++++ #+ Ruiy(R) Techdiss contact: 150 5519 8367 #+ ...
- 任务管理器进程中多个chrome.exe的问题
偶然发现任务管理器进程中有多个chrome.exe进程,非常奇怪自己仅仅打开了一次浏览器,为什么会有多个?! 上网一查才发现:原来使用Google浏览器Google Chrome每开一个新标签页面,都 ...
- oc 根据文件路径获取文件大小
第一种封装: -(NSInteger)getSizeOfFilePath:(NSString *)filePath{ /** 定义记录大小 */ NSInteger totalSize = ; /** ...
- iOS退出键盘的两种方式
1,可以让叫出键盘的那个控件,退出第一响应者; 例如:textField叫出的键盘,那么就可以调用textField.resignFirstResponder,达到谁叫出的键盘谁退回去 2,可以让叫出 ...
- json(转)
转自:http://www.cnblogs.com/mcgrady/archive/2013/06/08/3127781.html 阅读目录 JSON的两种结构 认识JSON字符串 在JS中如何使用J ...
- ASP.Net连接WebServer使用Https协议(证书)
ASP.Net使用Https(证书)协议连接WebService 最近使用ASP.Net连接WebService,不过走的协议是Https的,我一般用的使用都是普通的http协议.所以刚开始有点不值从 ...