2171 Board Overlay
time limit: 1 sspace limit: 32000 KBtitle level: Golden Gold SolvingTitle Description
Description
Give a n*n (n<=100) chess board, in which some points were removed and asked how many 1*2 dominoes could be used to cover up.
Enter a description
Input Description
First Behavior n,m (indicates a lattice with M delete)
The second line to m+1 acts X, Y, respectively, indicating where the delete lattice is located
X is line X
Y is the nth column
Output description
Output Description
A number, that is, the maximum number of overlay cells
Sample input
Sample Input
8 0
Sample output
Sample Output
32
Data range and Tips
Data Size & Hint
Classic Questions
Category labels
Tags Click here to expandNo label
Hungary
/*In fact, if the international chessboard as a set of white, black as set B. Each legal lattice and the adjacent legal lattice has a non-edge (legal is not deleted),//This maximum match is the so-called maximum coverage number. */#include<cstdio>#include<cstring>#include<iostream>using namespacestd;Const intdx[]={0,0,1,-1};Const intdy[]={1,-1,0,0};Const intn=1e4+Ten;Const intv= the;intn,m,num,ans,tot,mp[v][v],id[v][v],match[n],yy[n],head[n],next[n<<2],list[n<<2]; voidAddintXinty) {list[++tot]=y; Next[tot]=Head[x]; HEAD[X]=tot;}BOOLInsideintXinty) { returnX>0&&x<=n&&y>0&&y<=N;}BOOLHungaryintx) { for(intI=head[x];i;i=Next[i]) { if(!Yy[list[i]]) {Yy[list[i]]=1; if(!match[list[i]]| |Hungary (Match[list[i])) {Match[list[i]]=x; return 1; } } } return 0;}voidmapping () { for(intI=1; i<=n;i++){ for(intj=1; j<=n;j++) {Id[i][j]=++num; } } for(intI=1; i<=n;i++){ for(intj=1+! (i&1); j<=n;j+=2){ if(Mp[i][j])Continue; for(intk=0;k<4; k++){ intnx=i+dx[k],ny=j+Dy[k]; if(Inside (Nx,ny) &&!Mp[nx][ny]) {Add (Id[i][j],id[nx][ny]); } } } }}voidsolve () { for(intI=1; i<=n;i++){ for(intj=1+! (i&1); j<=n;j+=2){ if(Mp[i][j])Continue; Memset (yy,0,sizeofyy); if(Hungary (Id[i][j])) ans++; }} printf ("%d", ans);}intMain () {scanf ("%d%d",&n,&m); for(intI=1, x,y;i<=m;i++) scanf ("%d%d", &x,&y), mp[x][y]=1; Mapping (); Solve (); return 0;}
Network flow
/*idea: We can dye the board, black and white, that is, two different colors, so dyeing color, we can be the same color as a set of lattice, another color as a set, and then the adjacent lattice between the existence of the relationship between the side (of course, to exclude the part of the dig). Finding the maximum matching of binary graphs*/#include<cstdio>#include<iostream>using namespacestd;Const intdx[]={0,0,1,-1};Const intdy[]={1,-1,0,0};Const intn= About;Const intm=n*N;Const intinf=0x3f3f3f3f;intn,m,s,t,num,id[n][n],mp[n][n],head[m],dis[m],q[m*5];structnode{intV,next,cap;} E[m*Ten];inttot=1;voidAddintXintYintz) {e[++tot].v=y;e[tot].cap=z;e[tot].next=head[x];head[x]=tot; e[++tot].v=x;e[tot].cap=0; e[tot].next=head[y];head[y]=tot;}BOOLBFs () { for(inti=s;i<=t;i++) dis[i]=inf; intH=0, t=1; Q[t]=s;dis[s]=0; while(h!=t) { intx=q[++h]; for(intI=head[x];i;i=E[i].next) { intv=e[i].v; if(e[i].cap&&dis[v]>dis[x]+1) {Dis[v]=dis[x]+1; if(v==t)return 1; q[++t]=v; } } } returndis[t]<inf;}intDfsintXintf) { if(x==t)returnF; intUsed=0, T; for(intI=head[x];i;i=E[i].next) { intv=e[i].v; if(e[i].cap&&dis[v]==dis[x]+1) {T=Dfs (V,min (f,e[i].cap)); E[i].cap-=t;e[i^1].cap+=T; F-=t;used+=T; if(!f)returnused; }} Dis[x]=0; returnused;}intDinic () {intres=0; while(BFS ()) res+=DFS (S,inf); returnRes;}voidmapping () { for(intI=1; i<=n;i++){ for(intj=1; j<=n;j++) {Id[i][j]=++num; } } for(intI=1; i<=n;i++){ for(intj=1; j<=n;j++){ if(Mp[i][j])Continue; if((I+J) &1^1) {Add (S,id[i][j],1); for(intk=0;k<4; k++){ intnx=i+dx[k],ny=j+Dy[k]; if(nx<1|| nx>n| | ny<1|| ny>n| | Mp[nx][ny])Continue; Add (Id[i][j],id[nx][ny],1); } } Else{Add (Id[i][j],t,1); } } }}intMain () {scanf ("%d%d", &n,&m); s=0; t=n*n+1; for(intI=1, x,y;i<=m;i++) scanf ("%d%d", &x,&y), mp[x][y]=1; Mapping (); printf ("%d", Dinic ()); return 0;}
2171 Checkerboard Overlay