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模块之HTMLParser简介
html.parser是一个非常简单和实用的库,它的核心是HTMLParser类. 工作的流程是:当你feed给它一个类似HTML格式的字符串时,它会调用goahead方法向前迭代各个标签,并调用对应 ...
- 练习五十六:for循环
某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换 方法一: def o ...
- vue.js请求数据(axios)
使用npm安装axios npm install axios --save 在main.js中引入axios import axios from "axios"; 注册axios到 ...
- SpringMVC中的视图和视图解析器
对于控制器的目标方法,无论其返回值是String.View.ModelMap或是ModelAndView,SpringMVC都会在内部将它们封装为一个ModelAndView对象进行返回. Spri ...
- requirej入门nodeTpl使用(三)
基本语法 HTML部分 在模板中的 HTML 部分,使用定界符“<?”和“?>”作为语法的开始和结束. 在定界符内,可以书写任意JavaScript语句,如: <?for(var i ...
- wget访问tomcat管理界面
tomcat已经部署了管理界面,通过如下命令,将tomcat的状态信息打印到status.xml文件中,对于不方便使用浏览器访问该页面的情况,还是很有用的. wget http://localhost ...
- javasript数据类型以及如何判断数据类型
在javascript里面一共有5种基本的数据类型,分别是:Number,String,Boolean,Null,Undefined7种引用类型,分别是:Object类型,Array类型,Date类型 ...
- SQLiteOpenHelper 升级onUpgrade 的调用问题
onUpgrade 的调用次数问题 比如说现在数据库版本是1,然后此时我修改代码定数据库版本为5. 那么系统在调用onUpgrade的时候是只调用一次(oldVersion == 1, newVers ...
- 2019.03.19 读书笔记 string与stringbuilder的性能
1 string与stringbuilder 并不是stringbuilder任何时候都在性能上占优势,在少量(大约个位数)的字符串时,并不比普通string操作快. string慢的原因不是stri ...
- CAD安装失败怎样卸载CAD 2016?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...