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 ...
随机推荐
- ASP.NET下运用Memcached
对于大型网站的高并发,在ASP.NET网站下的session性能并不高,所以造成人们一种印象,大型WEB项目使用JAVA的错觉,致使很多人吐槽微 软不给力,其实这好比拉不出怪地球引力,本文介绍Memc ...
- switch的case中不能做定义
switch的case中不能做定义 只能给语句 error: a label can only be part of a statement and a declaration is not a st ...
- 在SQL脚本中的注释引起的奇怪问题
在数据库安装包中,我们通过osql.exe这个工具来对相关的数据库脚本进行更新,昨天突然发现安装包报错了,说脚本错误,但我们将脚本拿到数据库查询分析器中执行,一切OK. 问题出在哪里呢? 通过使用os ...
- JAVA MemCache 史无前例的详细讲解【转】
非原创转自:http://nhy520.iteye.com/blog/1775893 这篇文章是我看到的介绍的比较详细的,入门级别算是足足够了 Memcach什么是Memcache Memcache集 ...
- C#获取“所有用户桌面”的路径
想用C#得到The All Users Desktop(Public\Desktop)的路径. 原来以为很简单,然而 Environment.GetFolderPath(Environment.Spe ...
- jquery横向滚动条
此代码献给wendy 由于工作太忙,下次再整理成插件调用,先记录下来,欢迎同学们提意见. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...
- 解决CxGrid Filter 后,通过 Dataset 循环时得出的结果与 Grid显示不同步的问题.
// 方案1: 强制cxgrid 使用 dataset的 Filter GridMaster.DataController.Filter.AutoDataSetFilter := True; /// ...
- wxPython 基本框架与运行原理 -- App 与 Frame
<wxPython in Action> chapter 1.2 笔记 wxPython 是 wxWidgets 的 Python 实现,“w” for Microsoft Windows ...
- Python执行效率测试模块timei的使用方法与与常用Python用法的效率比较
timeit模块用于测试一段代码的执行效率 1.Timer类 Timer 类: __init__(stmt="pass", setup="pass", time ...
- InnoDB外键使用小结
USE `wfc_database`; # 主表(也可以称作:被参照表.referenced table.outTable) ALTER TABLE `app` ENGINE=INNODB; # 从表 ...