POJ 3283 Card Hands

/*

http://acm.pku.edu.cn/JudgeOnline/problem?id=3283

Trie树,最终插入的结点的数量
状态不好写code就是恶心,这么简单的题,犯了那么多恶心的错误
*/
#include <iostream>
#define MAX_N 100100
using namespace std;

int trieTree[MAX_N + 1][13][4];
int countv, total;

char temp[60][5];

void getP(char * const & temp, int &p1, int &p2)
{
    char c1, c2;
    if(strlen(temp) == 3)
    {
        p1 = 9;
        c2 = temp[2];
    }
    else
    {
        c1 = temp[0];
        c2 = temp[1];
    }
    if(strlen(temp) != 3)
    {
        if(c1 >= '2' && c1 <= '9')
            p1 = c1 - '1';
        else
        {
            if(c1 == 'A')
                p1 = 0;
            else if(c1 == 'J')
                p1 = 10;
            else if(c1 == 'Q')
                p1 = 11;
            else
                p1 = 12;
        }
    }
    if(c2 == 'C')
        p2 = 0;
    else if(c2 == 'D')
        p2 = 1;
    else if(c2 == 'H')
        p2 = 2;
    else
        p2 = 3;
}
void insert()
{
    int sLen, i, p1, p2;
    cin>>sLen;
    for(i = 0; i < sLen; i++)
        scanf("%s", temp[i]);
    int curPos = 0, next;
    for(i = sLen - 1; i >= 0; i--)
    {
        getP(temp[i], p1, p2);
        next = trieTree[curPos][p1][p2];
        if(next == 0)
        {
            trieTree[curPos][p1][p2] = next = ++countv;
            total++;
        }
        curPos = next;
    }
}
int main()
{
    int listNum, c;
    while(scanf("%d", &listNum) && listNum != 0)
    {
        memset(trieTree, 0, sizeof(trieTree));
        countv = total = 0;
        for(c = 0; c < listNum; c++)
            insert();
        cout<<total<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值