Load Balancing

给出每个学生的学分。   将学生按学分分成四组,使得sigma (sumi-n/4)最小。         算法:   折半枚举

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; int num[MS]; // 学分为i的人数
int sum[MS]; // 学分<=i的人数 int main()
{
int T,kase=,n,x;
scanf("%d",&T);
while(T--)
{
memset(num,,sizeof(num));
memset(sum,,sizeof(sum));
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&x);
num[x]++;
}
sum[]=num[]; // note: sum[0]!=0;
for(int i=;i<MS;i++)
sum[i]=sum[i-]+num[i];
// 折半枚举
int ansa,ansb,ansc;
int ta,tc;
double sum1,sum2,sum3=INF;
double ave=double(n)/4.0;
for(int b=;b<MS-;b++)
{
sum1=INF*1.0;
sum2=INF*1.0;
for(int a=;a<b;a++)
{
double t=fabs(double(sum[a])-ave)+fabs(double(sum[b]-sum[a])-ave);
if(t<sum1)
{
sum1=t;
ta=a;
}
} for(int c=b+;c<MS-;c++)
{
double t=fabs(double(sum[c]-sum[b])-ave)+fabs(double(sum[MS-]-sum[c])-ave);
if(t<sum2)
{
sum2=t;
tc=c;
}
}
if(sum1+sum2<sum3)
{
sum3=sum1+sum2;
ansa=ta;
ansb=b;
ansc=tc;
}
}
printf("Case %d: %d %d %d\n",kase++,ansa,ansb,ansc);
}
return ;
}

Load Balancing 折半枚举大法好啊的更多相关文章

  1. UVA 12904 Load Balancing 暴力

    Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...

  2. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  3. 【架构】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 ...

  4. 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 ...

  5. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  6. [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 ...

  7. 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 ...

  8. Network Load Balancing Technical Overview--reference

    http://technet.microsoft.com/en-us/library/bb742455.aspx Abstract Network Load Balancing, a clusteri ...

  9. NYOJ 1091 超大01背包(折半枚举)

    这道题乍一看是普通的01背包,最最基础的,但是仔细一看数据,发现普通的根本没法做,仔细观察数组发现n比较小,利用这个特点将它划分为前半部分和后半部分这样就好了,当时在网上找题解,找不到,后来在挑战程序 ...

随机推荐

  1. CodeForces 709A Juicer (水题, 模拟)

    题意:给定 n 个桔子的大小,一个杯子的容积,一个最大限度,挨着挤桔子汁,如果大小大于限度,扔掉,如果不杯子满了倒掉,问你要倒掉多少杯. 析:直接按要求模拟就好,满了就清空杯子. 代码如下: #pra ...

  2. 实现jsp网页设为首页功能

    var url = location.href; var browser_name = navigator.userAgent; if(browser_name.indexOf('Chrome')!= ...

  3. maven 基础整理

    教程 依赖管理 IDE设置121 IntelliJ,Edit Configurations中添加maven,选中 Resolve Workspace artifacts能自动编译依赖模块 内置命令 m ...

  4. C#委托的介绍(delegate、Action、Func、predicate)(转)

    委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递.事件是一种特殊的委托. 1.委托的声明 (1). delegate delegate我们常用到的一种声明   Deleg ...

  5. cocos2dx 屏幕适配策略

    cocos2dx的常用函数: CCEGLView::sharedOpenGLView()->setDesignResolutionSize() //设计分辨率大小(即开发时为基准的屏幕分辨率) ...

  6. ARM architectures

    https://gitorious.org/freebsd/freebsd/raw/56c5165837bf08f50ca4a08c6b2da91f73852960:sys/arm/include/a ...

  7. SAE J1850 VPW PWM, SAE J2411 SWC, ISO 11898 CAN, SAE J1708, Chrysler CCD 接口芯片电路

    SAE J1850 VPW 接口芯片电路 SAE J1850 PWM 接口芯片电路 SAE J2411 SWC 接口芯片电路 ISO 11898 CAN 接口芯片电路 CANH 和CANL 上的电容 ...

  8. Mysql权限控制 - 允许用户远程连接

    Mysql为了安全性,在默认情况下用户只允许在本地登录,可是在有此情况下,还是需要使用用户进行远程连接,因此为了使其可以远程需要进行如下操作: 一.允许root用户在任何地方进行远程登录,并具有所有库 ...

  9. Codeforces Round #310 (Div. 1) C. Case of Chocolate set

    C. Case of Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/ ...

  10. linux C(hello world) 二维数组的练习