随笔分类 - 二分匹配&&二分图
摘要:```//只有出现墙的时候,才会出现一行/列多个点的情况//那么可以考虑缩点,以行为例//如果某一行没有墙,那么这一列整体所成一个点//如果有墙,那么把没有墙的部分缩成一个点//当换行时,记得点数++ #include#include #define INF 0x3f3f3f3f#define LL long longconst int N=1000+5;using namespace std;i...
阅读全文
posted @ 2020-03-04 14:55
晴屿
摘要:```#include #include using namespace std;const int M=100000+5;int n;int h[M*2],mx[M*2],my[M*2];int vis[M];int e[M*2],ne[M*2],idx;int read(){ int res=0,ch,flag=0; if((ch=getchar())=='-') ...
阅读全文
posted @ 2020-03-03 16:19
晴屿
摘要:```//构建二分图#include #include typedef long long ll;using namespace std;const int N=155;const int INF=0x3f3f3f3f;struct Edge { int from,to;} edge[N*N];int tot,n,m;int read() { int res=0,ch,flag=0; if((ch...
阅读全文
posted @ 2020-03-03 15:59
晴屿
摘要:```#include using namespace std;const int maxn = 505;bool g[maxn][maxn], vis[maxn];int match[maxn];int val[maxn], keep[maxn];int a[maxn], b[maxn], c[maxn], d[maxn];int t, n, h, m;bool dfs(int u) { for...
阅读全文
posted @ 2020-03-03 15:41
晴屿
摘要:```#include#includeusing namespace std;const int N=1e5;const int maxn=1e3;int e[N],ne[N],h[N],idx;void add(int a,int b){ e[idx]=b; ne[idx]=h[a]; h[a]=idx++;}int n,m,xN,yN;int link[N],num[maxn][maxn],m...
阅读全文
posted @ 2020-03-03 15:24
晴屿
摘要:```#include#includeusing namespace std;typedef long long LL;const int N = 5e3+10;int map[110][110];int match[N], st[N];int n, m, k;bool dfs(int x){ for (int i = 1;i <= m;i++) { if (map[x]...
阅读全文
posted @ 2020-03-03 15:03
晴屿
摘要:```#include#include#includeusing namespace std;const int N=1e5;//点数的最大值int e[N],ne[N],idx,h[N];int K,M,N;void init() { idx=0; memset(h,-1,sizeof(h));}void addedge(int a,int b) { e[idx]=b; ne[idx]=h[a]...
阅读全文
posted @ 2020-03-03 14:56
晴屿
摘要:```#include #define PI acos(-1.0)#define E 1e-9#define INF 0x3f3f3f3f#define LL long longconst int N=1000+5;using namespace std;int n;bool vis[N];//vis[i]表示是否在交替路中int match[N];//存储连接点int e[N],ne[N],h[...
阅读全文
posted @ 2020-03-03 14:17
晴屿
摘要:```//首先将池塘舍去,然后将所有 i+j 为偶数的点当作 x,//将所有 i+j 为奇数的点当作 y,//然后直接拿 (x,y) 寻找增广路,//通过上下左右进行查找匹配,//再通过 link[x1][y1]=(x2,y2) 来记录匹配点#include#define LL long longconst int N=1000+5;const int dx[]= {-1,1,0,0};const...
阅读全文
posted @ 2020-03-03 11:20
晴屿
摘要:```//判断每个气球需要多少次才能扎破//大于k的,那么就不满足条件//可以看作最小点覆盖问题//分为两个集合,横坐标集合,纵坐标集合//然后每个点的坐标在这两个集合中且两点之间有连线//然后就是求最小点覆盖 #include#include#include#include#include#include#includeusing namespace std;const int maxn = 1...
阅读全文
posted @ 2020-03-03 10:51
晴屿
摘要:```#include using namespace std;const int N=510,M=100010;int e[M],ne[M],h[N],idx,ans;bool st[N];int n,m,num,a;int match[N];void add(int a,int b) { e[idx]=b,ne[idx]=h[a],h[a]=idx++;}int find(int x) { f...
阅读全文
posted @ 2020-03-02 22:50
晴屿
摘要:```//匈牙利求最大匹配//从左边每个非匹配点出发,做一遍增广,标记所有经过的点,//左边所有未被标记的点,和右边所有被标记的点,加起来就是要构造的方案//左边所有的非匹配点,都被标记了,//右边所有的非匹配点,一定没有被标记//对于每一个匹配边,左右两点要么同时被标记,要么同时不被标记//那么左边剩下的未被标记的点,一定是匹配点//右边所有被标记的点,都是匹配点//不在匹配中的情况:左边的非匹...
阅读全文
posted @ 2020-03-02 22:29
晴屿
摘要:```#include #include #include #include using namespace std;const int N =1e5;int n;int h[N], e[N], ne[N], idx;int match[N];bool st[N];void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ...
阅读全文
posted @ 2020-03-01 00:06
晴屿
摘要:#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010, M = 200010; int n, m; int h[N], e[M], ne[M], id
阅读全文
posted @ 2019-11-13 01:39
晴屿
摘要:#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 510, M = 100010; int n1, n2, m; int h[N], e[M], ne[M],
阅读全文
posted @ 2019-11-13 01:39
晴屿

浙公网安备 33010602011771号