UVA 12904 Load Balancing 暴力
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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int a[maxn];
double b[];
int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
memset(b,,sizeof(b));
int n=read();
for(int i=;i<n;i++)
a[i]=read(),b[a[i]]++;
for(int i=;i<=;i++)
b[i]+=b[i-];
double ans=inf;
int ans1,ans2,ans3;
double pp=n/4.0;
for(int i=;i<;i++)
{
for(int j=i+;j<;j++)
{
for(int k=j+;k<;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 暴力的更多相关文章
- 【架构】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 ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- 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 ...
- 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 ...
随机推荐
- C语言练习代码
1.运用for循环根据输入的金字塔层数,输出金字塔 eg: #include <stdio.h>int main(void){ int i,j,num; printf("请输入三 ...
- java webservice AXIS
1. eclipse axis 插件下载地址 http://archive.apache.org/dist/ws/axis2/tools/1_4_1/ 一个是代码生成插件 axis2-ecli ...
- 【LeetCode】242 - Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...
- PHP 解压zip文件的函数封装
/** * zip文件解压 * * @param $zipFilePath zip文件的路径,可以不加zip文件后缀.如果其他类型的文件伪装成zip解压也会失败 * @param $directory ...
- [转] 編程風格要素-The Elements of Programming Style 中文英文中英對照
转自: http://www.loliman3000.com/tech/2fe33ce32906f0302412881.php 下面的程序風格規則提煉自Brian Kernighan和P. J. Pl ...
- Linux下U盘的挂载和文件的拷贝
把文件通过U盘拷贝到linux系统下插好U盘后,查看磁盘情况fdisk -l正常情况下有 Disk /dev/sda:2045 MB,2045247488 bytes47 heads,46 secto ...
- Maven 包命令
1.必须选中项目,然后单击Run As,选择Maven build. 2.在配置窗体中的Goals栏填写clean package. 注意:Installed JREs中配置的JREs的位置必须是JD ...
- 20150926kaggle Titanic入门篇excel&python
1 excel数据透视表 这里主要是讲述了一下插入里面的数据透视表常用功能,数据透视表十分方便,比直接筛选还要简单,看数据很直观,这里大力推荐. 2 python&pandas 这里主要是讲述 ...
- Redhat=》中文
我的redhat安装时没有提示语言选项,由于工程需要,支持汉字是不可避免的,因此就必须安装中文输入法. 安装中文包 将系统光盘镜像文件连接至计算机,我的镜像是RHEL5.1的,先将光盘挂载至/mnt目 ...
- F2063 Could not compile used unit 'tt.pas'
install packge error F2063 Could not compile used unit 'tt.pas' 有可能是工程的pas文件相对路径不对.在工程管理看是否能打开文件,如果打 ...