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. 风险识别工具 - 影响图(Influence Diagram)

    原文地址:http://blog.csdn.net/jameszhou/archive/2007/06/24/1664494.aspx PMBOK(2004 3rd 英) P248关于风险识别的图形技 ...

  2. ajax 工作原理以及其优缺点

    1.什么是AJAX?AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.它使用:使用XHTML ...

  3. hxq的库

    在页面中使用 可以调取html模板 /** * Created by DY040 on 2017/10/31. */ var hxq = { init: function () { var self ...

  4. vue-基于elementui自定义主题更换皮肤及自定义内容的皮肤跟换

    参考这篇博客https://blog.csdn.net/young_Emily/article/details/78591261做一遍,加上自己的一些理解 思路:通过自己上一篇博客https://ww ...

  5. SQL 还原或备份失败数据库变成单个用户模式无法访问

    还原数据失败了,数据库变成单个用户模式,无法操作了,执行下面的语句就可以了 USE master GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @S ...

  6. Spring集成Quartz的3种方式

    1.使用xml配置方式 Maven依赖 <properties> <!-- spring版本号 --> <spring.version>4.2.2.RELEASE& ...

  7. python 编程,应该养成哪些好的习惯

    python 编程,应该养成哪些好的习惯? https://www.zhihu.com/question/28966220 无缓冲输出 python -u  sys.stdout.flush() 性能 ...

  8. Unity Transform

    public class PlayerControll : MonoBehaviour { Transform playerTransform; Animation playerAnimation; ...

  9. ubuntu 16.04 安装genymotion

     以ubuntu 16.04 64bit 系统为例: 1. 下载      通过https://www.genymotion.com/download/  下载自己操作系统版本的可执行文件(     ...

  10. IAR6.1的工程迁移到IAR6.5不能用的解决方法

    1.重命名过时的CMSIS头文件 "... \ CMSIS \ CM3 \ CoreSupport \ core_cm3.h  比如:core_cm3.h.old 2.启用CMSIS:项目- ...