UVALive 3231 Fair Share
Fair Share
This problem will be judged on UVALive. Original ID: 3231
64-bit integer IO format: %lld Java class name: Main
You are given N processors and M jobs to be processed. Two processors are specified to each job. To process the job, the job should be allocated to and executed on one of the two processors for one unit of time. If K jobs are allocated to a processor, then it takes K units of time for the processor to complete the jobs. To complete all the jobs as early as possible, you should allocate the M jobs to the N processors as fair as possible. Precisely speaking, you should minimize the maximum number of jobs allocated to each processor over all processors. The quantity, minimum number of jobs, is called fair share.
For example, you are given 5 processors and 6 jobs. Each job can be allocated to one of the two processors as shown in the table below. Job 1 can be allocated to processors 1 or 2, and job 2 can be allocated to processors 2 or 3, etc. If you allocate job 1 to processor 1, job 2 to processor 2, job 3 to processor 3, job 4 to processor 4, job 5 to processor 5, and job 6 to processor 1, then you have at most two jobs allocated to each processor. Since there are more jobs than processors in this example, some processors necessarily have at least two jobs, and thus the fair share is two.

Given N processors, M jobs, and the sets of two processors to which the jobs can be allocated, you are to write a program that finds the fair share. Processors are numbered from 1 toN and jobs are numbered from 1 to M . It is assumed that the sets of two processors to which the jobs can be allocated are distinct over all jobs.
That is, if a job J1 can be allocated to processors P1 or P2, and a job J2 which is different from J1 can be allocated to processors P3 or P4, then {P1, P2}
{P3, P4}.
Input
The input consists of T test cases. The number of test cases T is given in the first line of the input file. Each test case begins with a line containing an integer N, 1
N
1, 000, that represents the number of processors in the test case. It is followed by a line containing an integer M, 1
M
10, 000, that represents the number of jobs. In the following M lines, K-th line contains two distinct integers representing processors to which job K can be allocated, 1
K
M. The integers given in a line are separated by a space. After that, the remaining test cases are listed in the same manner as the above.
Output
Print exactly one line for each test case. The line should contain the fair share for that test case.
The following shows sample input and output for three test cases.
Sample Input
3
5
6
1 2
2 3
3 4
4 5
5 1
1 3
3
2
3 2
1 2
6
6
1 2
3 4
4 6
6 5
5 3
6 3
Sample Output
2
1
2
Source
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
} e[];
int head[maxn],d[maxn],cur[maxn],tot,S,T;
void add(int u,int v,int flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
q.push(T);
memset(d,-,sizeof d);
d[T] = ;
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i^].flow > && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[S] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow > && d[e[i].to]+== d[u]&&(a=dfs(e[i].to,min(e[i].flow,low)))){
e[i].flow -= a;
low -= a;
e[i^].flow += a;
tmp += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int ret = ;
while(bfs()){
memcpy(cur,head,sizeof head);
ret += dfs(S,INT_MAX);
}
return ret;
}
int u[maxn*],v[maxn*],n,m;
bool build(int mid) {
memset(head,-,sizeof head);
tot = ;
for(int i = ; i <= n; ++i)
add(S,i,mid);
for(int i = ; i <= m; ++i) {
add(n + i,T,);
add(u[i],n+i,);
add(v[i],n+i,);
}
return dinic() >= m;
}
int main() {
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
for(int i = ; i <= m; ++i)
scanf("%d%d",u+i,v+i);
S = ;
T = n + m + ;
int low = ,high = m,ret;
while(low <= high){
int mid = (low + high)>>;
if(build(mid)){
ret = mid;
high = mid - ;
}else low = mid + ;
}
printf("%d\n",ret);
}
return ;
}
UVALive 3231 Fair Share的更多相关文章
- uvalive 3231 Fair Share 公平分配问题 二分+最大流 右边最多流量的结点流量尽量少。
/** 题目: uvalive 3231 Fair Share 公平分配问题 链接:https://vjudge.net/problem/UVALive-3231 题意:有m个任务,n个处理器,每个任 ...
- LA 3231 - Fair Share
You are given N processors and M jobs to be processed. Two processors are specified to each job. To ...
- uvalive 3231
3231 - Fair ShareAsia - Seoul - 2004/2005You are given N processors and M jobs to be processed. Two ...
- LA3231 Fair Share 二分_网络流
Code: #include<cstdio> #include<vector> #include<queue> #include<cstring> #i ...
- UVALive 3231 网络流
题目要求给m个任务分配给n个机器,但最后任务量最多的那个机器的任务量尽量少,利用最大流,在最后的汇点那里设置关卡,二分结果,把机器到最终汇点的容量设置为该值,这样就达到题目条件,这样跑最大流 还能把m ...
- UVALive 5583 Dividing coins
Dividing coins Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...
- 三:Fair Scheduler 公平调度器
参考资料: http://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/FairScheduler.html http://h ...
- 大数据之Yarn——Capacity调度器概念以及配置
试想一下,你现在所在的公司有一个hadoop的集群.但是A项目组经常做一些定时的BI报表,B项目组则经常使用一些软件做一些临时需求.那么他们肯定会遇到同时提交任务的场景,这个时候到底如何分配资源满足这 ...
- [大数据之Yarn]——资源调度浅学
在hadoop生态越来越完善的背景下,集群多用户租用的场景变得越来越普遍,多用户任务下的资源调度就显得十分关键了.比如,一个公司拥有一个几十个节点的hadoop集群,a项目组要进行一个计算任务,b项目 ...
随机推荐
- java+selenium自动化遇到confirm弹窗,出现NoAlertPresentException: no alert open
//操作js的confirm弹窗,bool控制是否点击确定,true为点击确定,false为点击取消 public static void OperaterJSOfConfirm(WebDriver ...
- vue+Ueditor集成 [前后端分离项目][图片、文件上传][富文本编辑]
后端DEMO:https://github.com/coderliguoqing/UeditorSpringboot 前端DEMO:https://github.com/coderliguoqing/ ...
- Cocos2d-x碰撞检測
假设不适用Box2D物理引擎.那么要进行Cocos2d-x的碰撞检測那我们的方法往往就是进行"矩形和点"."矩形和矩形"这样粗略的碰撞检測.我们一般採取开启sc ...
- C语言--指针(一)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenVveW91MTMxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- 【leetcode 字符串处理】Compare Version Numbers
[leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Com ...
- js保留两位小数的解决的方法
var a = 123.456; a = a..toFixed(2); alert(a);//结果:123.46
- Bitcoin学习篇之---PPS和PPLNS挖矿模式介绍
PPS和PPLNS挖矿模式介绍 比特币每10分钟产生一个区块,会有千万人竞争.而这个区块终于仅仅归1个人全部.其他人都颗粒无收. 你或许要挖5年才干获得一个区块. 组队挖矿就是.一旦队伍里不论什么人获 ...
- php5.5安装笔记
这次没想到本来很简单的php编译,没想到遇到那么多问题.再此记录一下. 1.php5.5编译安装主要有一个难点,就是GD库的问题,因为php5.5的GD库必须是2.1以上的版本哦 原来都是用的gd2. ...
- poj--1985--Cow Marathon(树的直径)
Cow Marathon Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 4424 Accepted: 2214 Case ...
- maven冲突管理及依赖管理实践
1.“最近获胜策略(nearest wins strategy)”的方式处理依赖冲突 Maven采用“最近获胜策略(nearest wins strategy)”的方式处理依赖冲突,即如果一个项目最终 ...