The main topic: Give N*m Matrix and r,c. To find the minimum path coverage.
Originally a Hungarian algorithm naked problem, network flow can also run a run.
But I'm going to stick to a cheat. Big mistake Solution:
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intn,m,r,c,a[ -],ans;Charmp[ -][ -];intuse[ -][ -],cov[ -][ -];intMain () {//freopen ("legion.in", "R", stdin);//freopen ("Legion.out", "w", stdout);scanf"%d%d%d%d",&n,&m,&r,&c); for(intI=1; i<=n;i++) {scanf ("%s", mp[i]+1); for(intj=1; j<=m;j++) {A[i]+ = (mp[i][j]=='.'); if(mp[i][j]=='x') use[i][j]=1; } ans+=A[i]; } for(intI=1; i<=n;i++) { if(i>r) { for(intj=1; j<=m;j++) { if(mp[i][j]=='x')Continue; if(j>c&&use[i-r][j-c]==0) {Use[i-r][j-c]=1; COV[I][J]=1; Ans--; }Else if(j+c<=m&&use[i-r][j+c]==0) {Use[i-r][j+c]=1; COV[I][J]=1; Ans--; } } } if(r!=c&&i>c) { for(intj=1; j<=m;j++) { if(Cov[i][j])Continue; if(mp[i][j]=='x')Continue; if(j>r&&use[i-c][j-r]==0) {Use[i-c][j-r]=1; COV[I][J]=1; Ans--; }Else if(j+r<=m&&use[i-c][j+r]==0) {Use[i-c][j+r]=1; COV[I][J]=1; Ans--; } }}} printf ("%d\n", ans); Fclose (stdin); Fclose (stdout); return 0;}
This is what I wrote when I was in the exam (because I didn't listen to the Hungarian algorithm and the network stream), but no brain cheated 60?
Put it on a valley to test 70?
with all due respect, the figures are very strong.
Next is the whole solution:
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineN 55intn,m,r,c,hed[n*n],cnt;CharMp[n][n];structeg{intTO,NXT;} e[4*n*N];voidAeintFintt) {e[++cnt].to =T; E[CNT].NXT=Hed[f]; HED[F]=CNT;}intTnintXintY) {return(X-1) *m+y;}intdx[4],dy[4],fa[n*N];BOOLvis[n*N];intDfsintX//Hungary{vis[x]=1; for(intj=hed[x];j;j=e[j].nxt) { intto =e[j].to; if(!Vis[to]) {Vis[to]=1; if(!fa[to]| |DFS (Fa[to])) {Fa[to]=x; return 1; } } } return 0;}intMain () {//freopen ("legion.in", "R", stdin);//freopen ("Legion.out", "w", stdout);scanf"%d%d%d%d",&n,&m,&r,&c); dx[0]=dx[1]=dy[2]=r,dx[2]=dx[3]=dy[0]=c,dy[1]=-c,dy[3]=-R; for(intI=1; i<=n;i++) scanf ("%s", mp[i]+1); for(intI=1; i<=n;i++) { for(intj=1; j<=m;j++) { if(mp[i][j]=='.') { for(intk=0;k<4; k++) { intx = I+dx[k],y = j+Dy[k]; if(x<=0|| y<=0|| x>n| | Y>M)Continue; if(mp[x][y]=='.') AE (TN (I,J), TN (x, y)); } } } } intAns =0; for(intI=1; i<=n;i++) { for(intj=1; j<=m;j++) { if(mp[i][j]=='.') {memset (Vis,0,sizeof(VIS)); Ans+ = (Dfs (TN (i,j)) = =0); }}} printf ("%d\n", ans); return 0;}
[National training team] tribal war