标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1045
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define N 310 using namespace std; char maps[N][N]; int G[N][N], vis[N], used[N]; int n, x, y, a[N][N], b[N][N]; bool Find(int u) { int i; for(i = 1 ; i <= y ; i++) { if(!vis[i] && G[u][i]) { vis[i] = 1; if(!used[i] || Find(used[i])) { used[i] = u; return true; } } } return false; } void Build() { int i, j; x = y = 0; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for(i = 1 ; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(maps[i][j] == ‘.‘) { if(maps[i][j - 1] == ‘.‘) a[i][j] = a[i][j - 1]; else a[i][j] = ++x; } } } for(i = 1 ; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(maps[i][j] == ‘.‘) { if(maps[i - 1][j] == ‘.‘) b[i][j] = b[i - 1][j]; else b[i][j] = ++y; G[a[i][j]][b[i][j]] = 1; } } } } int main() { int i, j, ans; while(scanf("%d", &n), n) { ans = 0; memset(G, 0, sizeof(G)); for(i = 1 ; i <= n ; i++) { getchar(); for(j = 1 ; j <= n ; j++) scanf("%c", &maps[i][j]); } Build(); memset(used, 0, sizeof(used)); for(i = 1 ; i <= x ; i++) { memset(vis, 0, sizeof(vis)); if(Find(i)) ans++; } printf("%d\n", ans); } return 0; }
hdu 1045 Fire Net(最小覆盖点+构图(缩点))
标签:
原文地址:http://www.cnblogs.com/qq2424260747/p/4719181.html