POJ 3057 Evacuation (二分匹配)】的更多相关文章

题意:给定一个图,然后有几个门,每个人要出去,但是每个门每个秒只能出去一个,然后问你最少时间才能全部出去. 析:初一看,应该是像搜索,但是怎么保证每个人出去的时候都不冲突呢,毕竟每个门每次只能出一个人,并不好处理,既然这样,我们可以把每个门和时间的做一个二元组,然后去对应每个人,这样的话,就是成了二分图的匹配,就能做了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio&g…
题意:见挑战230页 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <map> #include <algorithm> #include <set> using…
Evacuation 题目连接: http://poj.org/problem?id=3057 Description Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushin…
每个门每个时间只能出一个人,那就把每个门拆成多个,对应每个时间. 不断增加时间,然后增广,直到最大匹配. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<…
题目 Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time, it may take a while for everyone…
这道题实现起来还是比较简单的,但是理解起来可能有点困难. 我最开始想到的是贪心法,每次消灭当前小行星最多的一行或一列.然而WA了.Discuss区里已经有高人给出反例. 下面给出正确的解法 我们把行和列抽象成点,把小行星抽象成边,每出现一个小行星,就把其行列所对应的点连起来.这样就形成了一个无向图$G=\left(V, E\right)$.问题就转化为了求这个图G中的最小点覆盖,即求一个元素数量尽可能小的点集$V' \subset V$,$E$中的所有边均与其内的一点相连. 最小点覆盖问题是一个…
分析: 这是一个时间和门的二元组(t,d)和人p匹配的问题,当我们固定d0时,(t,d0)匹配的人数和t具有单调性. t增加看成是多增加了边就行了,所以bfs处理出p到每个d的最短时间,然后把(t,d)和p连边,按t从小到大 枚举点增广就好了.无解的情况只有一种,某个人无论如何都无法出去. /********************************************************* * --Sakura hirahira mai orite ochite-- * * au…
[题目链接] http://poj.org/problem?id=3057 [题目大意] 给出一个迷宫,D表示门,.表示人,X表示不可通行, 每个门每时间单位只允许一个人通过, 每个人移动一格的为一时间单位的时间, 问所有人逃离这个迷宫的最小时间 [题解] 我们首先对于每个门进行搜索,求出其到每个人的最短时间, 之后我们将每扇门对于人来拆点,分别为这个人第几秒通过这个门 将拆点后的门对所有人做一遍顺序二分图匹配 匹配最终完成的时间的门是其第几个拆点那么时间就是第几秒 [代码] #include…
题目大意 POJ链接 有一个\(X×Y\)的房间,X代表墙壁,D是门,.代表人.这个房间着火了,人要跑出去,但是每一个时间点只有一个人可以从门出去. 问最后一个人逃出去的最短时间,如果不能逃出去,输出impossible. 输入格式 第一行一个整数\(T\),表示有T组数据. 每组数据,第一行两个数字\(Y,X\),接下来有一个\(X×Y\)的图. 输出格式 \(T\)行答案,表示最后一个人逃出去的最短时间,如果不能逃出去,输出impossible. 数据范围 \(3\le Y\le X\le…
Chessboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12800   Accepted: 4000 Description Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2…
原题 题目大意 墙壁"X",空区域(都是人)".", 门"D". 人向门移动通过时视为逃脱,门每秒能出去一个人,人可以上下左右移动,墙阻止移动. 求最优移动方案下,最后一个人逃脱的最短时间.如果有人无法安全逃脱(比如被墙围困住),则输出"impossible". 解析 对于每个时间进行网络流(二分图匹配人和门)直到匹配到的人数等于总人数的时候输出,最大时间是n*m,大于即为impossible #include<cstd…
题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值 下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说可以用DINIC跑二分图可以得到sqrt(v)*E的 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #incl…
很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> using namespace std; vector <int> edge[103]; int pre[303]; bool vis[303]; int n, m; bool dfs(int u) { for(int i = 0; i < (int)edge[u].size(); i++) { i…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16877   Accepted: 6627 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
Problem DescriptionFrank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While you can never exclude this possibility, he has made so…
题目链接:http://poj.org/problem?id=3057 题目大概意思是有一块区域组成的房间,房间的边缘有门和墙壁,'X'代表墙壁,'D'代表门,房间内部的' . '代表空区域,每个空区域站一个人,人可以向上下左右走,每走一步花费一秒钟,现在房间起火了,所有人向四周的门逃生,但是每秒钟一扇门只能通过一个人,每个人移动到门时,就算逃脱,问在选取使得所有人最优的逃生方案时,最后一个逃生的人花费多长时间?如果有人无法逃生,输出impossible. 题目建图思路比较难想.考虑到任意 t…
The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 10695 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering p…
The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16396   Accepted: 7502 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr…
POJ 2289(多重匹配+二分) 把n个人,分到m个组中.题目给出每一个人可以被分到的那些组.要求分配完毕后,最大的那一个组的人数最小. 用二分查找来枚举. #include<iostream> #include<string> #include<cstring> #include<cstdio> using namespace std; int map[1010][510]; int vis[1010]; int link[1010][510]; int…
Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 Description Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coordination of the cabs in order to pick up…
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开始想,把人看成顶点,若有暗恋的关系,就连一条边,构成一个图 独立集的概念:一个图中两两互不相连的顶点集合 所以这道题,就是要求最大独立集 有:最大独立集+最小顶点覆盖=|V|(顶点的总个数) 那就求最小顶点覆盖了 根据题意: 暗恋的对象性别不同,所以a暗恋b,b暗恋c,c暗恋a这种关系不可能存在 也…
题意:除了所给的一些点外,问能不能用1*2的矩形覆盖所有的点,矩形间不能重叠. 思路:简单二分匹配,,,,,,, #include<stdio.h> #include<string.h> const int N=1200; int match[N],link[N],map[35][35],n,m; int dir[4][2]={0,1,0,-1,1,0,-1,0}; int find(int u) { int i,v,x,y,X,Y; x=u/m;y=u%m; for(i=0;i&…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18993   Accepted: 7486 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
The dog task Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2559   Accepted: 1038   Special Judge Description Hunter Bob often walks with his dog Ralph. Bob walks with a constant speed and his route is a polygonal line (possibly self-in…
Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9754   Accepted: 3618 Description Rain has pummeled the cows' field, a rectangular grid of R rows and C columns (1 <= R <= 50, 1 <= C <= 50). While good for the grass, t…
Purifying Machine Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5004   Accepted: 1444 Description Mike is the owner of a cheese factory. He has 2N cheeses and each cheese is given a binary number from 00...0 to 11...1. To keep his chee…
Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 11694   Accepted: 5230 Description In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically in…
二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图. 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知道什么是最小点覆盖,我也在这里说一下:假如选…
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26760#problem/B Beloved Sons Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Once upon a time there liv…
POJ3057 Evacuation 二分图匹配+最短路 题目描述 Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time, it…