Annual Congress of MUD(最大流)
Annual Congress of MUD
时间限制: 1 Sec 内存限制: 128 MB
提交: 80 解决: 10
[提交] [状态] [讨论版] [命题人:admin]
题目描述
ACM is so popular that the event each year spans around 20 days. Each day, there will be a special gathering for MUD game designers to introduce their new games to the others.
Each player will usually spend a few days on the ACM site, and in-between will be invited in exactly one day to join this special gathering.
This year, ACM is held at your city, and your boss is an organiser, and he wants to find a best way to assign the players to these special gatherings (one player to one special gathering within his or her duration of stay), so that the maximum number of players among all gatherings is minimized.
Your boss is an extremely impatient guy. He wants to have a system that can tell the maximum number of players among all gatherings, in any best assignment, after each player enters his or her duration of stay. Your task is to help your boss develop such a system.
输入
输出
样例输入
3 3
1 1
1 1
1 1
3 3
1 2
2 3
1 1
3 3
1 2
1 2
1 2
0
样例输出
1 2 3
1
1 3
思路:将每个区间看作一个点,在源点s与输入的区间之间连一条流量为一的边,如果该区间已经存在,则将对应边的流量加一;
在每一个区间与区间内每一个点之间建一条流量为无穷的边;
在所有1~D的点与汇点t之间建一条流量为max的边,max为当前的the maximum number of players among all gatherings;
当然max起始为0.
#include <bits/stdc++.h>
using namespace std;
const int MAXN=;
const int INF=1e9+;
struct Max_flow
{
struct
{
int v,cap,next;
} e[MAXN*MAXN];
int cnt_edge,cur_clk,head[MAXN];
void init(int cnt)
{
cnt_edge=;
memset(head,0xff,sizeof(int)*cnt);
}
int add_edge_(int u,int v,int cap)
{
e[cnt_edge]={v,cap,head[u]};
head[u]=cnt_edge;
return cnt_edge++;
}
int add_edge(int u,int v,int cap)
{
int res=add_edge_(u,v,cap);
add_edge_(v,u,);
return res;
}
int clk[MAXN],pre[MAXN];
queue<int> que;
bool bfs(int s,int t)
{
while(!que.empty()) que.pop();
cur_clk++;
clk[s]=cur_clk;
que.push(s);
while(!que.empty())
{
int u=que.front();
que.pop();
for(int i=head[u]; i!=-; i=e[i].next)
{
if(e[i].cap>)
{
int v=e[i].v;
if(clk[v]!=cur_clk)
{
pre[v]=i;
clk[v]=cur_clk;
if(v==t) return true;
que.push(v);
}
}
}
}
return false;
}
int max_flow(int s,int t)
{
int flow=;
while(bfs(s,t))
{
int min_cap=INF;
for(int u=t;u!=s;u=e[pre[u]^].v)
{
if(min_cap>e[pre[u]].cap) min_cap=e[pre[u]].cap;
}
for(int u=t; u!=s; u=e[pre[u]^].v)
{
e[pre[u]].cap-=min_cap;
e[pre[u]^].cap+=min_cap;
}
flow+=min_cap;
}
return flow;
}
} G;
int vis[][],idx[][],edg_t[],s_edg[MAXN];
int n,d,now,m,s,t,flow;
bool flag;
int main()
{
while(scanf("%d",&n)!=EOF && n)
{
now++,m=,flow=,flag=false;
scanf("%d",&d);
for(int i=;i<d;i++)
{
for(int j=i;j<d;j++)
{
idx[i][j]=m++;
}
}
G.init(m+d+);
s=m+d,t=m+d+;
for(int i=;i<d;i++) edg_t[i]=G.add_edge(m+i,t,);
for(int i=;i<n;i++)
{
int x,y;
scanf("%d %d",&x,&y);
x--,y--;
int v=idx[x][y];
if(vis[x][y]!=now)
{
vis[x][y]=now;
for(int i=x;i<=y;i++) G.add_edge(v,m+i,INF);
s_edg[v]=G.add_edge(s,v,);
}
else
{
G.e[s_edg[v]].cap++;
}
flow+=G.max_flow(s,t);
//cout<<"ni"<<"->"<<flow<<endl;
if(flow!=i+)
{
if(flag) printf(" ");
else flag=true;
printf("%d",i+);
for(int i=;i<d;i++) G.e[edg_t[i]].cap++;
}
}
puts("");
}
return ;
}
Annual Congress of MUD(最大流)的更多相关文章
- Annual Congress of MUD
Annual Congress of MUD 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Multiuser dungeon games, also called MUD games ...
- Ural1109_Conference(二分图最大匹配/匈牙利算法/网络最大流)
解题报告 二分图第一题. 题目描写叙述: 为了參加即将召开的会议,A国派出M位代表,B国派出N位代表,(N,M<=1000) 会议召开前,选出K队代表,每对代表必须一个是A国的,一个是B国的; ...
- 使用C#处理基于比特流的数据
使用C#处理基于比特流的数据 0x00 起因 最近需要处理一些基于比特流的数据,计算机处理数据一般都是以byte(8bit)为单位的,使用BinaryReader读取的数据也是如此,即使读取bool型 ...
- HTML 事件(三) 事件流与事件委托
本篇主要介绍HTML DOM中的事件流和事件委托. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4 ...
- FILE文件流的中fopen、fread、fseek、fclose的使用
FILE文件流用于对文件的快速操作,主要的操作函数有fopen.fseek.fread.fclose,在对文件结构比较清楚时使用这几个函数会比较快捷的得到文件中具体位置的数据,提取对我们有用的信息,满 ...
- java.IO输入输出流:过滤流:buffer流和data流
java.io使用了适配器模式装饰模式等设计模式来解决字符流的套接和输入输出问题. 字节流只能一次处理一个字节,为了更方便的操作数据,便加入了套接流. 问题引入:缓冲流为什么比普通的文件字节流效率高? ...
- java 字节流与字符流的区别
字节流与和字符流的使用非常相似,两者除了操作代码上的不同之外,是否还有其他的不同呢?实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操作 ...
- BZOJ 3504: [Cqoi2014]危桥 [最大流]
3504: [Cqoi2014]危桥 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1407 Solved: 703[Submit][Status] ...
- java I/O流
输入流(读取数据的流) BufferedInputStream---继承--->FileInputStream--继承--->InputStream------> (1)字节流操作中 ...
随机推荐
- python学习:python文件中空格和换行符的捕获和文本文件的转存
0. 背景 之前公司的项目中,需要在嵌入式系统中实现一个http的网页端内容,由于项目历史遗留问题,公司是采用的将html文件转成c语言头文件的方式,每次修改页面端都需要从新编译一下程序,非常的繁琐. ...
- 在Docker中部署Asp.net core2.1以及修改发布
https://blog.csdn.net/sd7o95o/article/details/80809734 本篇文章主要是如何在Docker容器中运行ASP.NET Core应用程序,以及修改系 ...
- SQL SERVER – Configuration Manager – Cannot Connect to WMI Provider. You Do Not Have Permission or The Server is Unreachable
打开SQL SERVER Configuarion Manger 出现以下错误 SQL Server Configuration Manager—————————Cannot connect to W ...
- cesm1_2_2在南信大大型机上的移植以及运行简单case的步骤
真实验证有效:点击链接 查看具体移植过程.
- js 中callback函数的定义和使用
这是js里的解释了,其他语言的算我没说. 字面上理解下来就是,回调就是一个函数的调用过程.那么就从理解这个调用过程开始吧.函数a有一个参数,这个参数是个函数b,当函数a执行完以后执行函数b.那么这个过 ...
- maya2016无法安装卸载激活失败
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- [转]JS 只能输入数字和两位小数的JS
本文转自:http://blog.sina.com.cn/s/blog_724008890101dgep.html JS代码: <script language="JavaScript ...
- 牛客网Java刷题知识点之匿名对象、匿名对象的内存结构图、匿名对象的应用场景、匿名对象的使用、匿名对象的简单例子、匿名对象要注意的事项
不多说,直接上干货! 什么是匿名对象? 答: 没有名字的实体,也就是该实体没有对应的变量名引用. 没有名字的实体,没有引用类型变量指向的对象称作为匿名对象. 正常的,是 Car car = new ...
- fileupload NPOI导入EXECL数据
fileupload JS @section scripts{ <script src="~/Content/js/fileupload/vendor/jquery.ui.widget ...
- jQuery Validate验证框架详解(转)
jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...