The binary diagram of poj2446

Source: Internet
Author: User

Title:

id=2446 ">poj2446


Serie A champions: given a m*n matrix, in some places pits, and then 1*2 this article superimposed, repeatedly. Can put out the pit where all the other cover words output yes otherwise no


Analysis: There is a two-figure classic topic, of course, the difficulty is still a map, there is no idea, the early thought to be able to use (i-1) *m+j It every point in the matrix into a number, and then adjacent to the building map, Hungary, but do not know why is not correct? Ask the great God to explain, or understand not deep enough.


Very many people are based on their parity, because to be covered with 1*2 pieces of paper, then two values (I+J) must be an odd number of an even. And then to the figure of the odd number of points sequentially from 1 to start marking, adjacent to its label to build the map. Hungary, and relatively high speed. Positive Solution!

Because it must be an odd-numbered corresponding adjacent odd-numbered points. Then it is only possible to ask for the maximum matching of random odd or even numbers. The classic method of building a map.


Code:

#include <cstdio> #include <cstring> #include <string> #include <iostream> #include < Algorithm> #include <cmath>using namespace std;const int N = #define Del (x, y) memset (x,y,sizeof (×)) int map[        N][n],link[n],vis[n],vlink[n];int path[50][50];int n,m,t,tmp1,tmp2;bool dfs (int x) {for (int i=1; i<tmp2; i++) {            if (map[x][i]==1 && vis[i]==0) {vis[i]=1;                if (Link[i]==-1 | | dfs (LINK[I])) {link[i]=x;            return true; }}} return false;}    void Solve () {int ans=0;    Del (link,-1);    Del (vlink,-1);        for (int i=1; i<tmp1; i++) {Del (vis,0);    if (Dfs (i)) ans++;    }//printf ("%d\n", ans);    if (ans*2== (m*n-t)) printf ("yes\n"); else printf ("no\n");}    int main () {//freopen ("Input.txt", "R", stdin);        while (~SCANF ("%d%d", &n,&m)) {Del (path,0);        int x, y;     scanf ("%d", &t);           for (int i=0; i<t; i++) {scanf ("%d%d", &x,&y);        Path[y][x]=-1;        } tmp1=1,tmp2=1;                for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {if (path[i][j]==0)                    {if ((i+j)%2==0) path[i][j]=tmp1++;                else path[i][j]=tmp2++;        }}} Del (map,0); for (int i=1, i<=n; i++) {for (int j=1; j<=m; J + +) {if (Path[i][j]!=-1 &A mp;& (i+j)%2==1) {if (path[i-1][j]>=1) map[path[i-1][j]][p                    Ath[i][j]]=1;                    if (path[i+1][j]>=1) map[path[i+1][j]][path[i][j]]=1;                    if (path[i][j-1]>=1) map[path[i][j-1]][path[i][j]]=1;               if (path[i][j+1]>=1)         Map[path[i][j+1]][path[i][j]]=1;    }}} solve (); } return 0;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

The binary diagram of poj2446

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.