Annual Congress of MUD

时间限制: 1 Sec  内存限制: 128 MB
提交: 80  解决: 10
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Multiuser dungeon games, also called MUD games, are real-time virtual-world multiplayer games that are usually played online with text-based commands. The players do not meet normally, but every year, there is the Annual Congress of MUD (ACM) where MUD lovers all around the world could meet in person.
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.

输入

An instance of the problem consists of N + 1 lines. The first line specifies the integers N and D, seperated by a space. In the ith line of the following N lines, it contains two integers xi and yi , separated by a space. Note that the test data file may contain more than one instance. The last instance is followed by a line containing a single 0.

输出

For each instance, an integer i is marked if and only if the maximum number of players in the best assignment increases after the duration of stay [xi , yi ] of the ith player is keyed in. By default, 1 is always marked. The output of the corresponding instance is the list of all marked integers in ascending order, separated by a space between successive integers, followed by a newline character.

样例输入

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(最大流)的更多相关文章

  1. Annual Congress of MUD

    Annual Congress of MUD 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Multiuser dungeon games, also called MUD games ...

  2. Ural1109_Conference(二分图最大匹配/匈牙利算法/网络最大流)

    解题报告 二分图第一题. 题目描写叙述: 为了參加即将召开的会议,A国派出M位代表,B国派出N位代表,(N,M<=1000) 会议召开前,选出K队代表,每对代表必须一个是A国的,一个是B国的; ...

  3. 使用C#处理基于比特流的数据

    使用C#处理基于比特流的数据 0x00 起因 最近需要处理一些基于比特流的数据,计算机处理数据一般都是以byte(8bit)为单位的,使用BinaryReader读取的数据也是如此,即使读取bool型 ...

  4. HTML 事件(三) 事件流与事件委托

    本篇主要介绍HTML DOM中的事件流和事件委托. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4 ...

  5. FILE文件流的中fopen、fread、fseek、fclose的使用

    FILE文件流用于对文件的快速操作,主要的操作函数有fopen.fseek.fread.fclose,在对文件结构比较清楚时使用这几个函数会比较快捷的得到文件中具体位置的数据,提取对我们有用的信息,满 ...

  6. java.IO输入输出流:过滤流:buffer流和data流

    java.io使用了适配器模式装饰模式等设计模式来解决字符流的套接和输入输出问题. 字节流只能一次处理一个字节,为了更方便的操作数据,便加入了套接流. 问题引入:缓冲流为什么比普通的文件字节流效率高? ...

  7. java 字节流与字符流的区别

    字节流与和字符流的使用非常相似,两者除了操作代码上的不同之外,是否还有其他的不同呢?实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操作 ...

  8. BZOJ 3504: [Cqoi2014]危桥 [最大流]

    3504: [Cqoi2014]危桥 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1407  Solved: 703[Submit][Status] ...

  9. java I/O流

    输入流(读取数据的流) BufferedInputStream---继承--->FileInputStream--继承--->InputStream------> (1)字节流操作中 ...

随机推荐

  1. js模仿微信语音播放的小功能

    自己写的一个模仿微信语音播放的小功能,实现的主要功能是:点击播放,点击暂停,播放切换,,,  代码如下: <!DOCTYPE html> <html lang="en&qu ...

  2. hdfs shell命令及java客户端编写

    一. hdfs shell命令 可以通过hadoop fs 查看所有的shell命令及其用法. 传文件到hdfs: hadoop fs -put /home/koushengrui/Downloads ...

  3. maya2013安装失败如何卸载重装

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  4. Murano Weekly Meeting 2015.09.29

    Meeting time: 2015.September.29th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting s ...

  5. 安装mplayer2和smplayer2

    MPlayer2 PPA源安装,打开终端,输入命令: sudo add-apt-repository ppa:motumedia/mplayer-daily sudo apt-get update s ...

  6. React.js 小书 Lesson3 - 前端组件化(二):优化 DOM 操作

    作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson3 转载请注明出处,保留原文链接和作者信息. 看看上一节我们的代码,仔细留意一下 change ...

  7. HDU 4355——Party All the Time——————【三分求最小和】

    Party All the Time Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. phpstorm 配置 webserver ,配置根目录

    原文链接    http://blog.csdn.net/pony_maggie/article/details/52367093 phpstorm自带了一个web server,我们可以直接在IDE ...

  9. JAVA SE collection接口

    collection接口:{Set,List,Queue} Set:无序集合,元素不可重复          List:有序集合,元素可重复          Queue:队列 Set{EnumSet ...

  10. 【Android学习入门】Android studio基本设置

    1.背景设置 依次选择File->Settings-->Appearance & Behaviour->Apprearance,然后勾选 show line number. ...