网格图黑白染色,然后能互相攻击到的点之间连边,跑匈牙利算法最大匹配,答案是好点个数-最大匹配(最大独立集) 注意pao的时候只从一种颜色的格子统计即可 #include<iostream> #include<cstdio> using namespace std; const int N=205,dx[]={2,2,-2,-2,-1,-1,1,1},dy[]={-1,1,-1,1,-2,2,-2,2}; int n,m,sum,h[N*N],cnt,id[N][N],a[N][N]…
注意到怎么换都行,但是如果把某个黑方块用在对角线上,它原来所在的行列的的黑方块就都不能用 所以要选出n组不重的行列组合,这里用匈牙利算法做二分图匹配即可(用了时间戳优化) #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=405; int T,n,cnt,h[N],lk[N],v[N],ti; struct qwe { int ne,to; }e[…
匈牙利算法 var i,j,k,l,n,m,v,mm,ans:longint; a:..,..]of longint; p,f:..]of longint; function xyl(x,y:longint):boolean; var i,j,k,l:longint; begin if f[x]=y then exit(false); f[x]:=y; to m do ))or(xyl(p[i],y)))then begin p[i]:=x; exit(true); end; exit(fals…
Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a t…
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22809 Accepted: 10161 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering p…
题目链接:http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 12026 Accepted: 5355 Description In the second year of the university somebody started a study on the romantic relations between the stu…
在复习匈牙利算法的时候,发现这么一篇介绍匈牙利算法的文章,非常通俗易懂,所以就借鉴过来了. 复杂度:邻接矩阵:O(v^3)邻接表:O(V*E) 附上链接:趣写算法系列之--匈牙利算法 下面就附上代码吧: int maxn;//maxn 为x.y集合的最大顶点数 int xmatch[maxn]; //xmatch[i]表示X集合中的i在Y集合中对应的匹配 int ymatch[maxn]; //ymatch[i]表示Y集合中的i在X集合中对应的匹配 int map[maxn][maxn]; //…
Game with Pearls Problem DescriptionTom and Jerry are playing a game with tubes and pearls. The rule of the game is:1) Tom and Jerry come up together with a number K.2) Tom provides N tubes. Within each tube, there are several pearls. The number of p…
题意: 有一堆的学生关系,要将他们先分成两个组,同组的人都不互不认识,如果不能分2组,输出No.若能,则继续.在两组中挑两个认识的人(每组各1人)到一个双人房.输出需要多少个双人房? 思路: 先判定是否为二分图,可以用黑白着色法(DFS或BFS都行).若是二分图,再进行匹配,用匈牙利算法,注:给的是整个图,没有区分男女,用邻接表比较好. #include <bits/stdc++.h> #define LL long long using namespace std; ; vector<…
题意:中文题目 思路:匈牙利算法解决二分图最大匹配问题. #include <bits/stdc++.h> using namespace std; ; int mapp[N][N]; //矩阵 int girl[N]; //记录该女已分配的男编号 int vis[N]; //标记是否已经尝试为其另分配 int n, a, b, k, m; int find(int x) { ; i<=m; i++) //扫描所有妹子 { if(mapp[x][i]&&!vis[i])…