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练习六十:网页分析,找出里面的正文与链接
网页分析,找出里面的正文与链接 代码如下: from urllib import request from bs4 import BeautifulSoup request = request.url ...
- C++文件读写函数之——fopen、fread和fwrite、fgetc和fputc、fgets和fputs、ftellf和fseek、rewind
由于最近经常使用到c语言中的读写文件,所以在此总结以下,方便以后查找. 在c中,文件操作都是由库函数来实现的,主要是分为读和写两种操作,以下详细讲解以下所有有关文件操作的邯郸乎的用法: //C++写入 ...
- 使用EventBus实现兄弟组件之间的通信
使用EventBus实现兄弟组件之间的通信 需求:为了实现菜单折叠的效果,例如http://blog.gdfengshuo.com/example/work/#/dashboard header组件和 ...
- Linux虚拟机无法通过宿主机上网
解决方法 1.Windows: 确保相关服务已经启动 2.Linux: 确保相关服务已经启动 1) 确认Linux的IP地址和Windows在同一个网段: 若Windows给虚拟机分配的IP地址如下: ...
- Indexing the World Wide Web: the Journey So Far阅读笔记
文献文档用google搜索标题即可. term预处理:用空格切分,去除标点,去除撇号,归一化小写,去除变音符号,词干还原(?),去除停用词,挖掘词组. 索引选型工程最佳实践:term粒度.按doc分块 ...
- 3d Max 2013安装失败怎样卸载3dsmax?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- Unity Unity发布的ios包在iphone上声音小的原因
实质上声音是从话筒里出来的,未走扬声器. 仔细查找文档发现是PlayerSettings里的设置不当引起的. 在PlayerSettings取消勾选 Prepare iOS for Recording ...
- stm32 定时器初步
今天学习STM32 的通用定时器:TIMx (TIM2.TIM3.TIM4 和 TIM5). 定时器比较复杂,功能繁多,这里我们就说最基本的计数功能. 1.定时器的时钟从哪里来? 定时器的时钟来源有 ...
- Nodejs计时器定时执行函数
一.最low的定时器: 每次执行完间隔5s,然后继续执行 (function schedule() { setTimeout(do_it, 5000, schedule); }()); functio ...
- Docker 清理命令汇总
杀死所有正在运行的容器 docker kill $(docker ps -a -q) 删除所有已经停止的容器 docker rm $(docker ps -a -q) 删除所有未打 dangling ...