Chessboardtime limit:2000msmemory limit:65536kbthis problem'll be judged onPKU. Original id:2446
64-bit integer IO format: %lld Java class name: Main Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy-to-bob, so she-makes some holes on the board (as shown in the figure below).
We call a grid, which doesn ' t contain a hole, a normal grid. Bob have to follow the rules below:
1. Any normal grid should is covered with exactly one card.
2. One card should cover exactly 2 normal adjacent grids.
Some examples is given in the figures below:
A VALID solution.
An invalid solution, because the hole of red color are covered with a card.
An invalid solution, because there exists a grid, which are not covered.
Your task is to help Bob to decide whether or not the chessboard can being covered according to the rules above.InputThere is 3 integers in the first line:m, N, K (0 < M, n <=, 0 <= k < m * N), the number of rows, column A nd holes. In the next k lines, there are a pair of integers (x, y) in each line, which represents a hole in the y-th row, the X-th Co Lumn.OutputIf The board can be covered, output "YES". Otherwise, Output "NO".Sample Input
4 3 22) 13 3
Sample Output
YES
Hint
A possible solution for the sample input.SourcePOJ monthly,charlescpp Problem solving: Maximum match
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intMAXN = -* -;7 BOOLmp[maxn][maxn],used[maxn],cant[ -][ -];8 intlink[maxn],n,m,k;9 BOOLMatchintu) {Ten for(inti =0; i < MAXN; ++i) { One if(!mp[u][i] | | used[i])Continue; AUsed[i] =true; - if(Link[i] = =-1||match (Link[i])) { -Link[i] =u; the return true; - } - } - return false; + } - intMain () { + intx, y; A while(~SCANF ("%d%d%d",&n,&m,&k)) { atmemset (Cant,false,sizeofcant); - for(inti =0; I < K; ++i) { -scanf"%d%d",&y,&x); -cant[x-1][y-1] =true; - } -Memset (MP,false,sizeofMP); in for(inti =0; I < n; ++i) { - for(intj =0; J < M; ++j) { to if((I+J) &1) &&!Cant[i][j]) { + if(I >0&&!cant[i-1][J]) Mp[i*m + j][(i-1) *m + j] =true; - if(J >0&&!cant[i][j-1]) Mp[i*m + j][i*m + J-1] =true; the if(i +1< n &&!cant[i+1][J]) Mp[i*m + j][(i+1) *m + j] =true; * if(j +1< M &&!cant[i][j+1]) Mp[i*m + j][i*m + j +1] =true; $ }Panax Notoginseng } - } the intRET =0; +memset (link,-1,sizeofLink); A for(inti =0; I <= m*n; ++i) { thememset (Used,false,sizeofused); + if(Match (i)) + +ret; - } $printf"%s\n", n*m-k = =2*ret?"YES":"NO"); $ } - return 0; -}
View Code
POJ 2446 Chessboard