Topic Links:
Hdu 2236
Problem Solving Ideas:
The rows and columns are interpreted as the ends of the two-point graph, and the given matrix is all the edges in the two-minute graph.
If the binary graph can match exactly, then the n element interval of the different columns is (Min_edge,max_edge), which refers to those edges that make up the exact match
The problem needs to solve the minimum interval length
We can divide the interval length (0~100), the lower bound of each enumeration interval
The last Maxl is the answer.
Code:
#include <iostream> #include <cstdio> #include <cstring> #define MAXN 105using namespace Std;int map[ Maxn][maxn];int link[maxn];int vis[maxn];int n,minv,maxv;int maxl,minl,l,mid;int dfs (int u) {for (int i=1;i<=n;i++) {if (!vis[i]&&map[u][i]>=l&&map[u][i]<=l+mid) {vis[i]=1; if (link[i]==-1| | DFS (Link[i])) {link[i]=u; return 1; }}} return 0;} int hungry () {memset (link) (link,-1,sizeof); for (int i=1;i<=n;i++) {memset (vis,0,sizeof (VIS)); if (!dfs (i)) return false; } return true; int main () {int T; scanf ("%d", &t); while (t--) {minv=105,maxv=0; scanf ("%d", &n); for (int. I=1; i<=n; i++) for (int j=1; j<=n; J + +) {scanf ("%d", &map[i][j]); if (MAP[I][J]>MAXV) maxv=map[i][j]; if (MAP[I][J]<MINV) minV=MAP[I][J]; } MAXL=MAXV-MINV; minl=0; int flag; while (1) {mid= (MAXL+MINL) >>1; flag=0; for (l=minv;l+mid<=maxv;l++) if (hungry ()) {flag=1; Break } if (flag) Maxl=mid; if (minl==mid) break; if (!flag) Minl=mid; } printf ("%d\n", MAXL); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu 2236 Untitled II maximum match + two points