POJ 2062 & HDOJ 1528 Card Game Cheater-read comprehension... maximum matching of Bipartite Graph

Source: Internet
Author: User

Question:

I already know what card the first person will play in every round .. you have some cards on your hand .. ask how to win the most... the condition for victory is the ratio of size .. first, let's look at the partial order of the first digit (, T, J, Q, K,... if equal .. look at the partial order of the second (C, D, S, H...

Question:

If you can win... if you have enough edge... then run the maximum matching of the Bipartite Graph...

Program:

#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<stack>#include<string.h>#include<queue>#define ll long long#define esp 1e-5#define MAXN 55#define MAXM 100005#define oo 100000007using namespace std;  int n,A[MAXN][2],B[MAXN][2],match[MAXN];  bool g[MAXN][MAXN],used[MAXN];int turn(char c){       if (c>='2' && c<='9') return c-'2';       if (c=='T' || c=='C') return 8;       if (c=='J' || c=='D') return 9;       if (c=='Q' || c=='S') return 10;       if (c=='K' || c=='H') return 11;       return 12;}bool dfs(int x){       for (int i=1;i<=n;i++)          if (!used[i] && g[x][i])          {                 used[i]=true;                 if (!match[i] || dfs(match[i]))                 {                         match[i]=x;                         return true;                 }          }                 return false;}int getmax(){       int i,sum=0;       memset(match,0,sizeof(match));       for (i=1;i<=n;i++)       {               memset(used,false,sizeof(used));               sum+=dfs(i);       }              return sum;}int main(){                   int cases,i,j;       char c;          scanf("%d",&cases);       while (cases--)       {               scanf("%d",&n);               for (i=1;i<=n;i++)               {                       do { c=getchar(); }while (c==' '|| c=='\n');                       A[i][0]=turn(c);                       do { c=getchar(); }while (c==' '|| c=='\n');                       A[i][1]=turn(c);               }               for (i=1;i<=n;i++)               {                       do { c=getchar(); }while (c==' '|| c=='\n');                       B[i][0]=turn(c);                       do { c=getchar(); }while (c==' '|| c=='\n');                       B[i][1]=turn(c);               }               memset(g,false,sizeof(g));               for (i=1;i<=n;i++)                   for (j=1;j<=n;j++)                       if (B[i][0]>A[j][0] || (B[i][0]==A[j][0] && B[i][1]>A[j][1]))                           g[i][j]=true;               printf("%d\n",getmax());       }            return 0;  }  

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.