HDU1281 board game (binary match + find the necessary points)

Source: Internet
Author: User

Test instructions

Here's a map of N*m and a point on the K map where you can put your car.

Let you find out how many cars and which points are necessary (no match number will be reduced)

Ideas:

Hungary asks for the maximum match, and then one deletes the matching points to match,

If the number of matches is reduced after the point is deleted, this point is necessary

Code:

Starting with Vector to remember the point parameters to delete the trouble

/************************************************//author:d evil//created TIME:2016/5/10 17:22:52//*********** ************************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn= the; Vector<int>Eg[n];intLink[n],used[n],dx;BOOLVis[n];BOOLDfsintUintf) {     for(intI=0; I<eg[u].size (); i++)    {        intv=Eg[u][i]; if(!F&AMP;&AMP;U==DX&AMP;&AMP;V==USED[DX])Continue; if(!Vis[v]) {Vis[v]=1; if(link[v]==-1||DFS (LINK[V],F)) {Link[v]=u; if(f) used[u]=v; return 1; }        }    }    return 0;}intMain () {//freopen ("In.txt", "R", stdin);    intn,m,k,x,y,cas=0;  while(~SCANF ("%d%d%d",&n,&m,&k) {memset (link),-1,sizeof(link));  for(intI=1; i<= -; i++) eg[i].clear (); memset (Used,0,sizeof(used));  while(k--) {scanf ("%d%d",&x,&y);        Eg[x].push_back (y); }        intMa=0, ans=0;  for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); Ma+=dfs (I,1); }         for(intI=1; i<=n;i++)        {            if(Used[i]) {memset (link),-1,sizeof(link)); intnow=0; DX=i;  for(intj=1; j<=n;j++) {memset (Vis,0,sizeof(VIS)); now+=dfs (J,0); }                if(NOW!=MA) ans++; }} printf ("Board%d has%d important blanks for%d chessmen.\n",++Cas,ans,ma); }    return 0;}

And then simply write with the adjacency matrix.

/************************************************//author:d evil//created TIME:2016/5/10 17:23:18//*********** ************************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn= the;intlink[n],used[n],n,m,k;BOOLMp[n][n],vis[n];BOOLDfsintUintf) {     for(intI=1; i<=m;i++)    {        if(mp[u][i]&&!Vis[i]) {Vis[i]=1; if(link[i]==-1||DFS (LINK[I],F)) {Link[i]=u; if(f) used[u]=i; return 1; }        }    }    return 0;}intMain () {//freopen ("In.txt", "R", stdin);    intx,y,cas=0;  while(~SCANF ("%d%d%d",&n,&m,&k) {memset (link),-1,sizeof(link)); Memset (MP,0,sizeof(MP)); memset (Used,0,sizeof(used));  while(k--) {scanf ("%d%d",&x,&y); Mp[x][y]=1; }        intMa=0, ans=0;  for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); Ma+=dfs (I,1); }         for(intI=1; i<=n;i++)        {            if(Used[i]) {memset (link),-1,sizeof(link)); intnow=0; Mp[i][used[i]]=0;  for(intj=1; j<=n;j++) {memset (Vis,0,sizeof(VIS)); now+=dfs (J,0); } Mp[i][used[i]]=1; if(NOW!=MA) ans++; }} printf ("Board%d has%d important blanks for%d chessmen.\n",++Cas,ans,ma); }    return 0;}

HDU1281 board game (binary match + find the necessary points)

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.