Title Address: http://poj.org/problem?id=2446
This is the key to building a map. Since the cards are all 1*2, if Point v is covered by a 1*2 card, the other 1*2 areas surrounding v are not valid. So think of as long as the V-point in the X-set, the surrounding points in the Y set, V to the surrounding points are connected to each other, it becomes a two-figure matching problem, the difference between the Point V and the surrounding points can be used to the sum of the horizontal axis of parity. If the board can be covered with 1*2 cards except for obstacles, the maximum number of matches ans= (board all points n*m-number of obstacles K)/2. There is a small optimization before the subject, if the n*m-k is an odd number, it is obvious that it is not tenable, so return no directly.
1#include <cstdio>2#include <iostream>3#include <string.h>4#include <algorithm>5#include <math.h>6#include <stdbool.h>7#include <time.h>8#include <stdlib.h>9#include <Set>Ten#include <map> One#include <stack> A#include <queue> -#include <vector> - using namespacestd; the #defineCLR (x, y) memset (x,y,sizeof (×)) - #defineSQR (x) ((x) * (x)) - #defineRep (i,a,b) for (int i= (a); i<= (b); i++) - #defineLL Long Long + #defineINF 0x3f3f3f3f - #defineA First + #defineB Second A #definePI 3.14159265358979323 at Const intn= -+ One; - Const intdx[4]={0,0,1,-1}; - Const intdy[4]={1,-1,0,0}; - intN,m,k1,k,k2,f[n],g[n][n],link[n],flag[n][n],a[n],b[n]; - - voidInit () in { -CLR (F,0); toCLR (g,0); +CLR (flag,0); -CLR (A,0); theCLR (b,0); *CLR (link,-1); $k1=0;Panax NotoginsengK2=0; - } the + BOOLFindintx) A { the for(intI=0; i<k2;i++) { + if(!f[b[i]) &&G[x][b[i]]) { -f[b[i]]=1; $ if(link[b[i]]==-1||find (Link[b[i])) { $link[b[i]]=x; - return true; - } the } - }Wuyi the return false; - } Wu - intHungary () About { $ intcn1=0; - for(intI=0; i<k1;i++) { -CLR (F,0); - if(Find (A[i])) ans++; A } + returnans; the } - $ intMain () the { the intu,v,x,y; the the init (); -scanf"%d%d%d",&m,&n,&k); in if((m*n-k) &1) { theprintf"no\n"); the return 0; About } the for(intI=1; i<=m;i++) { the for(intj=1; j<=n;j++) theflag[i][j]=1; + } - for(intI=1; i<=k;i++) { thescanf"%d%d",&y,&x);Bayiflag[x][y]=0; the } the - for(intI=1; i<=m;i++) { - for(intj=1; j<=n;j++) { the the intp= (I-1) *n+J; the if((I+J) &1) { the if(Flag[i][j]) a[k1++]=p; -}Else { the if(Flag[i][j]) b[k2++]=p; the } the }94 } the the for(intI=1; i<=m;i++) { the for(intj=1; j<=n;j++) {98 if(Flag[i][j]) About for(intk=0;k<4; k++) { - intnx=i+Dx[k];101 intny=j+Dy[k];102 if(Flag[nx][ny]) {103g[(I-1) *n+j][(nx-1) *n+ny]=1;104 } the }106 }107 }108 109 if(2*hungary () +k==n*m) printf ("yes\n"); the Elseprintf"no\n");111 the return 0;113}
[POJ] 2446 chessboard (two-figure maximum match)