1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| #include <iostream> #include <cstring>
using namespace std; const int maxn = 35;
class solution { public: int n,m; bool g[maxn][maxn],vis[maxn]; int left[maxn];
void init(int n) { this->n = n; memset(g,0,sizeof g); memset(left,-1,sizeof left); }
bool match(int u) { for (int v=1; v<=n; ++v) if (g[u][v] && !vis[v]) { vis[v] = 1; if (left[v]==-1 || match(left[v])) { left[v] = u; return 1; } } return 0; } int solve() { int ans=0; for (int i=1; i<=n; ++i) { memset(vis,0,sizeof vis); if (match(i)) ++ans; } return ans; } };
int xmin[maxn],ymin[maxn],xmax[maxn],ymax[maxn]; struct { int num; bool use; } edge[maxn];
int main() { freopen("1.in","r",stdin); solution ss; int n,kase=0; while (scanf("%d",&n) && n) { ss.init(n); memset(edge,0,sizeof edge); for (int i=1; i<=n; ++i) scanf("%d%d%d%d",&xmin[i],&xmax[i],&ymin[i],&ymax[i]); for (int i=1; i<=n; ++i) { int x,y; scanf("%d%d",&x,&y); for (int j=1; j<=n; ++j) if (xmin[j]<=x && x<=xmax[j] && ymin[j]<=y && y<=ymax[j]) ss.g[j][i] = 1; } ss.solve(); int edge_num = n; for (int i=1; i<=n; ++i) { edge[ss.left[i]].num = i; edge[ss.left[i]].use = 1; } for (int i=1; i<=n; ++i) { int j = edge[i].num; ss.g[i][j] = 0; memset(ss.left,-1,sizeof ss.left); int num = ss.solve(); if (num == n) { edge[i].use = 0; --edge_num; } ss.g[i][j] = 1; } printf("Heap %d\n",++kase); if (edge_num == 0) printf("none\n"); else { for (int i=1; i<=n; ++i) if (edge[i].use) printf("(%c,%d) ",i-1+'A',edge[i].num); printf("\n"); } printf("\n"); } return 0; }
|