HDU 41,852-point map matching

Source: Internet
Author: User

Test instructions to cover the ' # ' in the matrix with 1*2 planks (only ' # ' to cover the planks), and ask for up to a few planks to cover

The # is abstracted as a two point, a plank is a match, note that the final result is divided by 2.

Sample Input

16.......##....##.......#.....## ...

Sample Outputcase 1:3
1#include <stdio.h>2#include <string.h>3 Const intmaxn= +;4 Charmap[610][610];5 inttt[610][610];6 intUN,VN;//Number of U,v7 intG[MAXN][MAXN];8 intLINKER[MAXN];9 BOOLUSED[MAXN];Ten BOOLDfsintu) One { A     intv; -      for(v=0; v<vn;v++) -         if(g[u][v]&&!Used[v]) the         { -used[v]=true; -             if(linker[v]==-1||DFS (Linker[v])) -             { +linker[v]=u; -                 return true; +             }     A         }   at     return false;  - }     - intHungary () - { -     intres=0; -     intu; inmemset (linker,-1,sizeof(linker)); -      for(u=0; u<un;u++) to     { +memset (Used,0,sizeof(used)); -         if(Dfs (U)) res++; the     }  *     returnRes;  $ }  Panax Notoginseng  - intMain () the { +     intT; A     intN; thescanf"%d",&T); +     intIcase=0; -     inttmp; $      while(t--) $     { -icase++; -scanf"%d",&n); the         -tmp=0;Wuyi          for(intI=0; i<n;i++) the         { -scanf"%s",&map[i]); Wu            for(intj=0; j<n;j++) -            if(map[i][j]=='#') tt[i][j]=tmp++; About         }     $Memset (G,0,sizeof(g)); -un=vn=tmp; -          for(intI=0; i<n;i++) -            for(intj=0; j<n;j++) A           { +               if(map[i][j]!='#')Continue; the               if(i>0&&map[i-1][j]=='#') g[tt[i][j]][tt[i-1][j]]=1; -               if(i<n-1&&map[i+1][j]=='#') g[tt[i][j]][tt[i+1][j]]=1; $               if(j>0&&map[i][j-1]=='#') g[tt[i][j]][tt[i][j-1]]=1; the               if(j<n-1&&map[i][j+1]=='#') g[tt[i][j]][tt[i][j+1]]=1; the           }      the          the         intres=Hungary (); -printf"Case %d:%d\n", icase,res/2); in     }     the     return 0; the}

HDU 41,852-point map matching

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.