POJ3283+字典树
简单的字典树
/*
字典树
构造字典树。注意初始化!
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int maxm = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-; int a[ maxm ];
struct tree{
tree* next[ maxn ];
//bool lev;
};
tree root;
int tot; int getval(char mod[],char aim)
{
int i;
for(i=;mod[i];i++)
{
if(mod[i]==aim)return i;
}
return -;
} int getval(char s[])
{
char value[]="A234567891JQK";
char suit[]="CDHS";
int a=getval(value,s[]);
int len=strlen(s);
int b=getval(suit,s[len-]);
return a*+b;
} void init(){
tot = ;
for( int i=;i<maxn;i++ )
root.next[i] = NULL;
//printf("AC=%d\n",getval("AC"));
//printf("AC=%d\n",getval("AD"));
//printf("AC=%d\n",getval("AH"));
//printf("AC=%d\n",getval("AS"));
//printf("KS=%d\n",getval("KS"));
} void build( int n ){
tree *p = &root;
tree *tmp;
for( int i=;i<=n;i++ ){
if( p->next[ a[i] ]==NULL ){
tmp = ( tree* )malloc( sizeof( root ) );
//tmp->lev = true;
for( int j=;j<maxn;j++ ){
tmp->next[j] = NULL;
}
p->next[ a[i] ] = tmp;
p = p->next[ a[i] ];
tot++;
}
else{
p = p->next[ a[i] ];
}
}
return ;
} int main(){
int m;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while( scanf("%d",&m)&&m> ){
int n;
init();
char tmp[ ];
for( int i=;i<=m;i++ ){
scanf("%d",&n);
//printf("i=%d\n",i);
for( int j=n;j>=;j-- ){
scanf("%s",tmp);
a[ j ] = getval(tmp);
}
//for( int j=1;j<=n;j++ )
//printf("%d ",a[j]);
//printf("\n");
build( n );
}
printf("%d\n",tot);
//delete(&root);
}
return ;
}
POJ3283+字典树的更多相关文章
- 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)
前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...
- 萌新笔记——C++里创建 Trie字典树(中文词典)(一)(插入、遍历)
萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...
- 山东第一届省赛1001 Phone Number(字典树)
Phone Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 We know that if a phone numb ...
- 字典树 - A Poet Computer
The ACM team is working on an AI project called (Eih Eye Three) that allows computers to write poems ...
- trie字典树详解及应用
原文链接 http://www.cnblogs.com/freewater/archive/2012/09/11/2680480.html Trie树详解及其应用 一.知识简介 ...
- HDU1671 字典树
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- *HDU1251 字典树
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- 关于RadAsm中GetEnvironmentStrings的BUG。
今天在asm中不通过msvcrt.inc调用c库. 所以.第一时间就在vc的lib中拷贝了libc.lib问价.加入工程后. 声明.调用如下: 然后.链接报错. libc.lib(crt0.obj) ...
- log4net基本日志使用笔记[windows application]
Ref: http://www.cnblogs.com/wangsaiming/archive/2013/01/11/2856253.html http://www.cnblogs.com/zhouf ...
- memcached 使用积累
1.memcahed在windows上的安装 . 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached . 在终端(也即cmd命令界面)下输入 ‘c:\memc ...
- 【DELPHI】线程相关
//准备让线程调用的测试函数 procedure Draw(aCanvas: TCanvas; X,Y: Integer; aCount: Integer = 100000); var i: Inte ...
- 学习W3SCHOOL 表单验证
//表单学习笔记 //建立一张表单的验证 <!DOCTYPE html> <html> <head> <meta http-equiv="Conte ...
- C语言宏定义取得两数的最大值和最小值
/*本程序时为了验证用宏来做 * 两个数的大小比较的写法*/#include<stdio.h>#define MAX(x,y) ((x)<(y)?(y):(x))#define MI ...
- C语言中的七种排序算法
堆排序: void HeapAdjust(int *arraydata,int rootnode,int len) { int j; int t; *rootnode+<len) { j=*ro ...
- .vimrc & .bashrc 文件配置
/* 如果vim还没有语法高亮,那么在/etc/profile 中添加以下语句 */ export TERM=xterm-color // 注: 只对各个用户自己的主目录下的.vimrc修改的话,修改 ...
- GNU_makefile_template
#g++ compiler: options # -std=c++0x enables ISO C++ 11 standard # -I.. pulls in the Version_test.h f ...
- EXTJS4.2 后台管理菜单栏
EXTJS 代码: 第一种方法: { title: '汽车信息管理', layout: 'fit', items: [ { xtype: 'treepanel', border: 0, rootVis ...