【POJ】3283 Card Hands
字典树。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
using namespace std; #define TRIEN 56 typedef struct Trie {
Trie *next[TRIEN];
Trie() {
for (int i=; i<TRIEN; ++i)
next[i] = NULL;
}
} Trie; Trie *root;
int nn; Trie *create(const char str[], Trie *r) {
int i = , id;
Trie *p = r, *q; if (str[i] == 'A')
id = ;
else if (str[i] == 'J')
id = ;
else if (str[i] == 'Q')
id = ;
else if (str[i] == 'K')
id = ;
else if (str[i]=='' && ++i)
id = ;
else
id = str[i] - '';
if (str[i+]=='D')
id += ;
if (str[i+]=='H')
id += ;
if (str[i+]=='S')
id += ;
if (p->next[id] == NULL) {
q = new Trie();
p->next[id] = q;
++nn;
}
p = p->next[id]; return p;
} void del(Trie *t) {
if (t == NULL)
return ;
for (int i=; i<TRIEN; ++i)
del(t->next[i]);
delete t;
} int main() {
int n, m;
string tmp;
stack<string> st;
Trie *r; while (scanf("%d", &n)!=EOF && n) {
root = new Trie();
nn = ;
while (n--) {
scanf("%d", &m);
while (m--) {
cin >> tmp;
st.push(tmp);
}
r = NULL;
while (!st.empty()) {
tmp = st.top();
st.pop();
if (r == NULL)
r = create(tmp.data(), root);
else
r = create(tmp.data(), r);
}
}
printf("%d\n", nn);
del(root);
} return ;
}
【POJ】3283 Card Hands的更多相关文章
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 【BZOJ3526】[Poi2014]Card 线段树
[BZOJ3526][Poi2014]Card Description 有n张卡片在桌上一字排开,每张卡片上有两个数,第i张卡片上,正面的数为a[i],反面的数为b[i].现在,有m个熊孩子来破坏你的 ...
- 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉
DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $ 当然这里的$i$和$k$都是偶数啦~ ...
- 【POJ】【2104】区间第K大
可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...
- 【POJ】1222 EXTENDED LIGHTS OUT
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...
- 【POJ】2892 Tunnel Warfare
[算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...
- 【POJ】【1637】Sightseeing tour
网络流/最大流 愚人节快乐XD 这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路…… 我们知道如果一个[连通]图中每个节点都满足[入度=出度]那么就一定有欧拉回路…… 那么每条边都可 ...
- 【poj】1001
[题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...
随机推荐
- Java语言基础(三)
Java语言基础(三) 一. 补码 (1).之所以有补码是因为要考虑成本 就是造计算机的成本 (2).下面让我们分析一下补码 以四位补码为例 <1> 高位是符号位,它决定其是正数还是 ...
- SQL Server 事务、异常
转自: http://www.cnblogs.com/moss_tan_jun/archive/2011/11/26/2263988.html 事务 在数据库中有时候需要把多个步骤的指令当作一个整 ...
- GridView 无数据时,绑定提示
private void BindData() { DataTable dt = DAO.RunSQLReturnDt(this.getsql()); int dtcount = dt.Rows.Co ...
- 【转】Windows环境下.NET 操作Oracle问题
目前,Windows操作系统可以分成两类,32位和64位(64位也区分x86_64位和Itanium ),同时Oracle客户端也做了同样的区分. 在安装和开发的过程中,经常会遇到一些问题,本文就总结 ...
- move file create directory.
If we want to move file to the directory that does not exist,and if we perform a File.Move,it will r ...
- C# 枚举
一.在学习枚举之前,首先来听听枚举的优点. 1.枚举能够使代码更加清晰,它允许使用描述性的名称表示整数值. 2.枚举使代码更易于维护,有助于确保给变量指定合法的.期望的值. 3.枚举使代码更易输入. ...
- 利用sfntly的sfnttool.jar提取中文字体
雨忆博客中提到了sfntly(具体介绍可以看:https://code.google.com/p/sfntly/),利用其中sfnttool.jar就可以提取只包含指定字符的字体,如果想在页面中通过@ ...
- 织梦dedecms后台发布文章不自动更新首页与栏目列表页
dedecms发文章不自动更新首页也列表页解决办法如下: 登陆dedecms后台,找到“系统”“系统基本参数”“性能选项”,把“arclist标签调用缓存”设置成0,然后把“发布文章后马上更新网站主页 ...
- 4种检测是否支持HTML5的方法,你知道几个?
4种检测是否支持HTML5的方法,你知道几个? 1,检查特定的属性是否存在于全局的对象里面,比如说window或navigator. 比如geolocation,它是HTML5新加支持的新特性:它是由 ...
- js时间戳转为日期格式
转自:http://wyoojune.blog.163.com/blog/static/57093325201131193650725/ 这个在php+mssql(日期类型为datetime)+aja ...