There are n slides of varying sizes (only the outlines and the numbers above are visible) A, B, C, D, E... Stacked in order. Now we know the size of each slide. Because the slides are transparent, we can see the numbers on the slides (given the coordinates of each number, but I don't know which slides these numbers belong to.) Now, you need to output a matched slide number and number based on the current known information. Idea: it is obvious that the problem of binary matching is to determine the matching, first find the maximum matching. Then, each edge is deleted in sequence, and the maximum matching value is obtained. If the maximum matching value is reduced, the matching value is determined.
//168K 0MS #include <stdio.h> #include <string.h> const int M = 30; struct Slide { int x1,x2,y1,y2; } slide[M]; int mat[M][M],link[M],cur[M],vis[M],n; int DFS(int u) { for (int v = 1; v<=n; v ++) { if (!vis[v]&&mat[u][v]) { vis[v] = 1; if(link[v] == -1||DFS(link[v])) { link[v] = u; return 1; } } } return 0; } int MaxMatch() { int u,res = 0; memset(link,-1,sizeof(link)); for (u = 1; u <= n; u ++) { memset (vis,0,sizeof(vis)); if (DFS(u)) res ++; } return res; } int main () { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int i,j,x,y; int cnt = 0; while (scanf ("%d",&n)&&n) { memset (mat,0,sizeof(mat)); for (i = 1; i <= n; i ++) scanf ("%d%d%d%d",&slide[i].x1,&slide[i].x2,&slide[i].y1,&slide[i].y2); for (i = 1; i <= n; i ++) { scanf ("%d%d",&x,&y); for (j = 1; j <= n; j ++) if (x>slide[j].x1&&x<slide[j].x2&&y>slide[j].y1&&y<slide[j].y2) mat[i][j] = 1; } printf ("Heap %d\n",++cnt); int Maxn = MaxMatch(); bool flag = false ; for (j = 1;j <= n;j ++) for (i = 1;i <= n;i ++) { if (!mat[i][j]) continue; mat[i][j] = 0; if (MaxMatch() < Maxn){ flag = true; printf ("(%c,%d) ",'A'+j-1,i); } mat[i][j] = 1; } if (!flag) printf ("none"); printf ("\n\n"); } return 0; }