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

题意

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

问你分界线是多少

题解:

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

代码

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <sstream>
  10. #include <queue>
  11. #include <typeinfo>
  12. #include <fstream>
  13. #include <map>
  14. #include <stack>
  15. typedef long long ll;
  16. using namespace std;
  17. //freopen("D.in","r",stdin);
  18. //freopen("D.out","w",stdout);
  19. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  20. #define test freopen("test.txt","r",stdin)
  21. #define maxn 2000001
  22. #define mod 1000000007
  23. #define eps 1e-9
  24. const int inf=0x3f3f3f3f;
  25. const ll infll = 0x3f3f3f3f3f3f3f3fLL;
  26. inline ll read()
  27. {
  28. ll x=,f=;char ch=getchar();
  29. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  30. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  31. return x*f;
  32. }
  33. //**************************************************************************************
  34.  
  35. int a[maxn];
  36. double b[];
  37. int main()
  38. {
  39. int t=read();
  40. for(int cas=;cas<=t;cas++)
  41. {
  42. memset(b,,sizeof(b));
  43. int n=read();
  44. for(int i=;i<n;i++)
  45. a[i]=read(),b[a[i]]++;
  46. for(int i=;i<=;i++)
  47. b[i]+=b[i-];
  48. double ans=inf;
  49. int ans1,ans2,ans3;
  50. double pp=n/4.0;
  51. for(int i=;i<;i++)
  52. {
  53. for(int j=i+;j<;j++)
  54. {
  55. for(int k=j+;k<;k++)
  56. {
  57. if(abs(b[i]-pp)+abs(b[j]-b[i]-pp)+abs(b[k]-b[j]-pp)+abs(n-b[k]-pp)<ans)
  58. {
  59. ans=abs(b[i]-pp)+abs(b[j]-b[i]-pp)+abs(b[k]-b[j]-pp)+abs(n-b[k]-pp);
  60. ans1=i,ans2=j,ans3=k;
  61. }
  62. }
  63. }
  64. }
  65. printf("Case %d: %d %d %d",cas,ans1,ans2,ans3);
  66. printf("\n");
  67. }
  68. }

UVA 12904 Load Balancing 暴力的更多相关文章

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

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

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

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

  4. Load Balancing 折半枚举大法好啊

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

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

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

  7. Network Load Balancing Technical Overview--reference

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

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

  9. NGINX Load Balancing – TCP and UDP Load Balancer

    This chapter describes how to use NGINX Plus and open source NGINX to proxy and load balance TCP and ...

随机推荐

  1. 我常用的Linux命令

    CD: ..        —-切换到上层目录 ~        —-回到家目录(/home/你的登录名/) LS: -a        —-显示指定目录所有文件,包括文件名以 . 开头的文件 -l  ...

  2. struts2类型转换与校验总结

    1.struts2的类型转换分为全部变量转变和局部变量转变. 2.struts2对8中常见的基本类型的属性变量,可以自动转换.如果是User对象,可以手动简历UserAction-coversion. ...

  3. SSD Cloud Hosting - Linode的配置和部署,搭建Java环境

    0.发牢骚 前一个月在淘宝购买了个Jsp空间,挺便宜的,才38元/年.部署了程序,然后ALIMAMA验证网站,一直提示验证失败.最后找卖家,他说可能是因为空间太慢,照他的推荐换了最好的空间,138元/ ...

  4. 图的邻接表存储表示(C)

    //---------图的邻接表存储表示------- #include<stdio.h> #include<stdlib.h> #define MAX_VERTEXT_NUM ...

  5. 多态.xml

    pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...

  6. 基类,派生类,内存分配情况 .xml

    pre{ line-height:1; color:#1e1e1e; background-color:#d2d2d2; font-size:16px;}.sysFunc{color:#627cf6; ...

  7. 怎么去掉Xcode工程中的某种类型的警告

    XCode警告   问题描述  在我们的项目中,通常使用了大量的第三方代码,这些代码可能很复杂,我们不敢改动他们,可是作者已经停止更新了,当sdk升级或者是编译器升级后,这些遗留的代码可能会出现许许多 ...

  8. 在Python中怎么表达True

    在Python中怎么表达True   为False的几种情况 0为False,其他所有数值皆为True 空串("")为False,其他所有字符串皆为True 空list([])为F ...

  9. ninject学习笔记一:IOC的实现

    这篇文章主要介绍ninject在IOC方面的实现,至于IOC的含义,网络资源很丰富,我这儿就不再赘述了.官方的文档其实挺好的,只是本人英语很烂,看起来比较费劲,下面这些东西是看官方的代码推敲的,我觉得 ...

  10. Camera拍照声设定

    在某些国家(比如Japan),为了防止偷拍,强制拍照声是需要从Speaker出来的(即使插入耳机的情况下). 实现该功能比较简单的方法就是将拍照声类型设置为Ringtone 或 Alarm 或 Not ...