标签:
Description
Input
Output
Sample Input
Sample Output
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 6 using namespace std; 7 8 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 9 //int main(int argc, char** argv) 10 11 #define N 1005 12 13 struct node 14 { 15 int x, y; 16 }P[N][N]; 17 18 int x, y, n, g[N][N], used[N], vis[N], ans; 19 char s[N][N]; 20 21 int found(int u) 22 { 23 for(int i = 1; i <= y; i++) 24 { 25 if(!vis[i] && g[u][i]) // 可以放 26 { 27 vis[i] = 1; 28 if(!used[i] || found(used[i])) 29 { 30 used[i] = u; 31 return true; 32 } 33 } 34 } 35 return false; 36 } 37 38 int main() 39 { 40 while(scanf("%d", &n), n) 41 { 42 ans = x = y = 0; 43 memset(g, 0, sizeof(g)); 44 memset(used, 0, sizeof(used)); 45 46 for(int i = 0; i < n; i++) 47 scanf("%s", s[i]); 48 49 for(int i = 0; i < n; i++) 50 { 51 for(int j = 0; j < n; j++) 52 { 53 if(s[i][j] == ‘.‘) 54 { 55 if(j == 0 || s[i][j-1] == ‘X‘) // 前边是墙就可以另开一行或列放东西 56 x++; 57 P[i][j].x = x; 58 } 59 if(s[j][i] == ‘.‘) 60 { 61 if(j == 0 || s[j-1][i] == ‘X‘) 62 y++; 63 P[j][i].y = y; 64 } 65 } 66 } 67 68 for(int i = 0; i < n; i++) 69 for(int j = 0; j < n; j++) 70 if(s[i][j] == ‘.‘) 71 g[P[i][j].x][P[i][j].y] = 1; // 如果这个位置可以放东西,当前行列可以匹配 72 73 for(int i = 1; i <= x; i++) 74 { 75 memset(vis, 0, sizeof(vis)); 76 if(found(i)) 77 ans++; 78 } 79 80 printf("%d\n", ans); 81 } 82 return 0; 83 }
标签:
原文地址:http://www.cnblogs.com/Tinamei/p/4721758.html