Load Balancing

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83008#problem/H

Description

The infamous University of Kala Jadu (UKJ) have been operating underground for the last fourteen centuries training very select few students the dangerous art of black magic. However, with the recent trend of going digital, they too wanted to try out a bit of public exposure by enrolling students in their new distance education program.
Within the first three semesters they have got 6,789 students enrolled. The forkaclone spell allows them to clone their teachers to train at most 10,000 students in a running semester. But they do not have the server capacity to handle 10,000 students to register for their courses right at the beginning of the semester during their 4-day registration period. Sadly, their art of black magic (or kala jadu, as they say), only works on humans, it cannot be extended to their web server running on a Pentium IV machine.
UKJ server administrators realized that if they could split the load on the server and balance it somehow, then they can still handle 10,000 students per semester. Their idea is to divide the students into roughly 4 equal groups A, B, C and D. Each group would then be given one day to register; no other group can register on that same day — they will get their turn. They wanted to use total number of credits completed by a student as the deciding factor to assign students to the 4 different groups. As the students who would register can have completed any integer number of credits between 0 to 160, one easy group assignment would be:
0 - 40 credits completed: group A
41 - 80 credits completed: group B
81 - 120 credits completed: group C
121 - 160 credits completed: group D
A bit of analysis of the number of students that may fall in these groups revealed that the number of students in each group vary greatly. So this particular idea of splitting students into 4 groups to balance the server load does not quite work out.
UKJ seeks your help in finding the credit boundaries that can create an optimal distribution of students so that each group roughly have the same number of students. You’d suggest three integers a, b and c to distribute the students as follows:
0 - a credits completed: group A
a + 1 - b credits completed: group B
b + 1 - c credits completed: group C
c + 1 - 160 credits completed: group D
If the total number of students is N, the best possible scenario would place N/4 students in each group. You need to minimize the sum of difference, d between N/4 and the number of student you place in each group. For example, given N = 8 students to distribute, if you divide them into a group of 3, 0, 3, 2 students then the difference with N/4 for the groups would be 1, 2, 1, 0 respectively. This results in 1 + 2 + 1 + 0 = 4 as sum of differences. This is what you’d have to minimize. Note that, N/4 can be a floating point number.

Input

The input description for the problem starts with T (1 < T 100) — the number of test cases, then T test cases follow. The first line of each case starts with the number of students N (0 < N 10000). The next N lines contains the number of credits (always integer), Ci (0 Ci 160) the i-th student have completed prior to this registration.

Output

Output for each test case will start with the test case label (starting with 1, and formatted as shown in sample output.) The label will be followed by three integers, a, b and c (0 a < b < c < 160) denoting the group boundaries as described in the problem. If there are multiple such boundaries possible with the same d value, then pick the solution that has the smallest a value. If there is a tie, then pick the one with the smallest b value. If even that fails to break the tie, then pick the solution with the smallest c value.

Sample Input

280
40
41
80
85
120
150
155
90
40
41
80
85
120
121
150
155

Sample Output

Case 1: 40 80 120
Case 2: 40 80 120

HINT

题意

这个学校要把学生按照分数分为四等人,要求每一等的人数都差不多

问你分界线是多少

题解:

直接暴力枚举分界线就吼了……

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//**************************************************************************************int a[maxn];
double b[200];
int main()
{int t=read();for(int cas=1;cas<=t;cas++){memset(b,0,sizeof(b));int n=read();for(int i=0;i<n;i++)a[i]=read(),b[a[i]]++;for(int i=1;i<=160;i++)b[i]+=b[i-1];double ans=inf;int ans1,ans2,ans3;double pp=n/4.0;for(int i=0;i<160;i++){for(int j=i+1;j<160;j++){for(int k=j+1;k<160;k++){if(abs(b[i]-pp)+abs(b[j]-b[i]-pp)+abs(b[k]-b[j]-pp)+abs(n-b[k]-pp)<ans){ans=abs(b[i]-pp)+abs(b[j]-b[i]-pp)+abs(b[k]-b[j]-pp)+abs(n-b[k]-pp);ans1=i,ans2=j,ans3=k;}}}}printf("Case %d: %d %d %d",cas,ans1,ans2,ans3);printf("\n");}
}

UVA 12904 Load Balancing 暴力相关推荐

  1. 科普|什么是负载均衡(Load balancing)

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 作者 | Enter 来源 | cnblogs.com/kingr ...

  2. 负载均衡(Load Balancing)学习笔记(二)

    概述 文章负载均衡(Load Balancing)学习笔记(一) 讲述了负载均衡的一般性原理,本文继续介绍常见的实现负载均衡的方法. HTTP重定向 HTTP重定向服务器是一台普通的Web服务器,用户 ...

  3. 网页加载出现没有合适的负载均衡器_终于讲清楚了,什么是负载均衡(Load balancing)...

    什么是负载均衡(Load balancing) 在网站创立初期,我们一般都使用单台机器对台提供集中式服务,但随着业务量越来越大,无论性能还是稳定性上都有了更大的挑战.这时候我们就会想到通过扩容的方式来 ...

  4. ASA/PIX: Load balancing between two ISP - options

    ASA/PIX: Load balancing between two ISP - options VERSION 7  Is it possible to load balance between ...

  5. nginx tcp代理_nginx——TCP/UDP Load Balancing

    nginx––– tcp and udp 代理 Introduction nginx 反向代理一般都是7层代理,进行http/https 协议层的转发:说起4层代理,一般想到的都是lvs 和 hapr ...

  6. Nginx(四):负载均衡Load balancing

    1.概念基础 Load balancing,即负载均衡,是一种计算机技术,用来在多个计算机(计算机集群).网络连接.CPU.磁盘驱动器或其他资源中分配负载,以达到最优化资源使用.最大化吞吐率.最小化响 ...

  7. 网络负载平衡(Network Load Balancing)的工作原理

    NLB算法的特点: 在NLB群集中,每台服务器都会有一个属于自己的静态IP地址,同时NLB群集中的所有服务器还有一个共同的IP地址-NLB群集地址: 当客户向NLB群集(NLB的虚拟IP地址)发起请求 ...

  8. PLB: Congestion Signals are Simple and Effective for Network Load Balancing读后思考

    这周我读的论文是PLB: Congestion Signals are Simple and Effective for Network Load Balancing.这篇论文是谷歌提出的一个建立在传 ...

  9. BZOJ4411 - [Usaco2016 Feb]Load balancing

    Portal Description 给出平面上的\(n(n\leq10^5)\)个整点.画两条直线\(x=x_0\)和\(y=y_0\)将这些点划分成\(s_1,s_2,s_3,s_4\)个点,最小 ...

最新文章

  1. 纯前端H5小应用_localStorage存储
  2. 图解字符串的朴素模式匹配算法
  3. UVA10780:Again Prime? No Time(数论)
  4. elasticsearch搜素关键字自动补全(suggest)
  5. python网络编程3-socketserver模块
  6. js判断定时器是否启动_原生js如何做出轮播图的效果
  7. object怎么转list_PaddleOCR识别模型转Pytorch全流程记录
  8. idea 自动生成补全变量名 快捷键
  9. java命令javac java,使用命令行JAVAC编译Java
  10. 三维点云学习(4)3-Model Fitting Least Square
  11. SQL笔试经典50题及答案解析(题目41-50)
  12. linux查看网卡物理编号_Linux下查看网卡信息
  13. Scrapy 爬取链家租房价格信息
  14. 利用python做中文词频分析
  15. python虚拟宠物猫
  16. OLED屏幕应用实验
  17. vue3之组件通信 (props父传子,子传孙)(ts定义数组类型)
  18. 创意名片大全:一组精美的折叠效果名片设计
  19. Altium designer 10安装破解以及出现缺少mfc71.dll文件的情况处理
  20. 蓝牙技术|2028 年智能音箱市场将达290亿美元,伦茨科技推出(Alexa,Echo音箱)亚马逊App直连幻彩灯方案

热门文章

  1. 哈夫曼算法(最优二叉树)
  2. 定位模块介绍及使用(GPS、北斗、GLONASS、伽利略、准天顶)
  3. 各种触发器的特性方程_薛定谔方程,究竟神奇在哪里?
  4. mysql php 全是字符串,PHP MySQL中有多个htmlspecialchars字符串
  5. Linux+QT界面开发(含数据库)小结
  6. [Swift]LeetCode17. 电话号码的字母组合 | Letter Combinations of a Phone Number
  7. 某些小技巧的技术分享
  8. 从资源管理器中,获取被选择的文件的路径(及文件夹)的API
  9. tensorflow学习笔记一:安装调试
  10. Recovery 流程简介