Question Link: Https://www.nowcoder.com/acm/contest/76/A
Ideas
The right and bottom of each ' # ' if it is also ' # ' indicates that the two points constitute the path, in order to reconstruct a picture, and then find the maximum match of the binary graph.
Code
#include <bits/stdc++.h>using namespacestd;Charmp[ -][ -];BOOLvis[2505];vector<int>g[2505];intmp1[ -][ -], match[2505], N;BOOLDfsintu) { for(inti =0; I < g[u].size (); i++) { intv =G[u][i]; if(!Vis[v]) {Vis[v]=1; if(Match[v] = =-1||DFS (Match[v])) {Match[v]=u; return 1; } } } return 0;}intMain () {intT, CAS =0; CIN>>T; while(t--) { intnum =0; scanf ("%d", &N); for(inti =0; I < n; i++) scanf ("%s", Mp[i]); for(inti =0; I < n; i++) for(intj =0; J < N; J + +) if(Mp[i][j] = ='#') Mp1[i][j] = + +num; for(inti =0; I < n; i++) for(intj =0; J < N; J + +) { if(Mp[i][j] = ='#') { if(mp[i+1][J] = ='#') G[mp1[i][j]].push_back (mp1[i+1][J]), g[mp1[i+1][j]].push_back (Mp1[i][j]); if(mp[i][j+1] =='#') G[mp1[i][j]].push_back (mp1[i][j+1]), g[mp1[i][j+1]].push_back (Mp1[i][j]); }} memset (Match,-1,sizeofmatch); intAns =0; for(inti =1; I <= num; i++) {memset (Vis,0,sizeofvis); if(Dfs (i)) ans++; } printf ("Case %d:%d\n", ++cas, ans/2); } return 0;}
"2018 National multi-school algorithm winter training Camp Practice Competition (fourth)-A" Oil acquisition (Hungarian algorithm)