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. 第三百三十一天 how can I 坚持

    今天加了一天班,好累,还没吃晚饭,回来只吃了个泡面. 晚上回来的路上,在群里聊的倒是很happy,快笑死我了,仲宫二少,哈哈. 弟弟过两天要去见面,多聊聊,该结婚来. 还有,中午吃的肯德基,不好吃,可 ...

  2. NHibernate的简单例子

    NHibernate的简单例子 @(编程) [TOC] 因为项目需求,搭了一个NHibernate的例子,中间遇到了一些问题,通过各种方法解决了,在这里记录一下最后的结果. 1. 需要的dll Com ...

  3. Java反射机制(创建Class对象的三种方式)

    1:了解什么是反射机制? 在通常情况下,如果有一个类,可以通过类创建对象:但是反射就是要求通过一个对象找到一个类的名称:   2:在反射操作中,握住一个核心概念: 一切操作都将使用Object完成,类 ...

  4. 使用python获得git中分支存成list

    通过这个搜集git工程下的branch信息例子,来说明一下python和终端的信息交互,和字符串的简单处理.代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  5. OracleCommand.CommandText 无效

    OracleCommand insertADataCmd = conn.CreateCommand(); insertBDataCmd.CommandText = SQL OracleParamete ...

  6. .Net实现的批量删除(使用了repeater控件)

    前台 <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> < ...

  7. How Tomcat Works(十八)

    在前面的文章中,如果我们要启动tomcat容器,我们需要使用Bootstrap类来实例化连接器.servlet容器.Wrapper实例和其他组件,然后调用各个对象的set方法将它们关联起来:这种配置应 ...

  8. 分享吉林大学机械科学与工程学院,zhao jun 博士的Halcon学习过程及知识分享

    分享吉林大学机械科学与工程学院,zhao jun 博士的Halcon学习过程及知识分享 全文转载zhao jun 博士的新浪博客,版权为zhaojun博士所有 原文地址:http://blog.sin ...

  9. springboot 学习笔记(一)

    引子 最近在搞一个项目,走在科技前沿的师兄, 摒弃了公司老套的框架模式, 采用了springboot搭建新应用.看到如此简洁的代码 , 深受诱惑.趁周末闲余之时, 背晒阳光, 学起了springboo ...

  10. putty 中文乱码解决方法

    解决putty.exe 中文乱码的问题 export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"