zoukankan      html  css  js  c++  java
  • HDU-1528/1962 Card Game Cheater

    两组牌中两张牌相比能赢的就连,后求最大匹配。

    #include <cmath>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <fstream>
    #include <iostream>
    
    #define rep(i, l, r) for(int i=l; i<=r; i++)
    #define clr(x, c) memset(x, c, sizeof(x))
    #define N 32
    #define MAX 1<<30
    #define ll long long
    
    using namespace std;
    int read()
    {
    	int x=0, f=1; char ch=getchar();
    	while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    	while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    	return x*f;
    }
    int read2()
    {
    	char s[5]; scanf("%s", s); int a;
    	if (s[0]=='T') a=32;
    	else if (s[0]=='J') a=36;
    	else if (s[0]=='Q') a=40;
    	else if (s[0]=='K') a=44;
    	else if (s[0]=='A') a=48;
    	else a=(s[0]-'2')*4;
    	if (s[1]=='H') a+=3;
    	else if (s[1]=='S') a+=2;
    	else if (s[1]=='D') a+=1;
    	return a;
    }
    
    struct edge{int y, n;} e[N*N]; int fir[N], en;
    int n, ka[N], kb[N], k[N], ans;
    bool b[N];
    
    void Add(int x, int y) { en++, e[en].y=y, e[en].n=fir[x], fir[x]=en; }
    
    bool Find(int x)
    {
    	int o=fir[x], y=e[o].y;
    	while (o)
    	{
    		if (!b[y])
    		{
    			b[y]=1; if (!k[y] || Find(k[y])) { k[y]=x; return true; }
    		}
    		o=e[o].n, y=e[o].y;
    	}
    	return false;
    }
    
    int main()
    {
    	int t=read(); while (t--)
    	{
    		clr(fir, 0); clr(k, 0); en=ans=0;
    		n=read();
    		rep(i, 1, n) ka[i]=read2();
    		rep(i, 1, n) kb[i]=read2();
    		rep(i, 1, n) rep(j, 1, n) if (kb[j] > ka[i]) Add(i, j);
    		rep(i, 1, n)
    		{
    			clr(b, 0); if (Find(i)) ans++;
    		}
    		printf("%d
    ", ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    关于mybatis中mapper.xmlSQL语句书写的心得
    笔记
    SpringMVC的小总结
    配置generatorConfig.xml自动生成的代码的sql书写问题
    关于SQL中的排序问题
    鼠标的change事件
    Git学习笔记 --第一章
    XHR对象
    黑马程序员——java学习6(127-151)——多线程
    黑马程序员——java学习5(107-126)——内部类,异常,包
  • 原文地址:https://www.cnblogs.com/NanoApe/p/4358071.html
Copyright © 2011-2022 走看看