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 ...
随机推荐
- Swift方法
Swift 中的方法是与特定类型(类和结构体)相关的函 数. 实例方法 隶属于某个特定类型(类或结构体)实例函数. class Counter{ var count = 0 funcincrement ...
- Cocoa框架中的内存分区
NSObject对象类实例为我们提供了两种分配内存的方式:alloc和allocWithZone:.alloc的实现也是为了调用allocWitZone:,它传入了一个默认的zone.所以明确的说,N ...
- XPath 初步讲解
2016-05-05 XPath是JavaScript 中节点查找手段,ie9以后的版本才支持w3c标准,其他浏览器基本支持.在e8之前的浏览器,通过基于 activeX的xml dom对象实现. 为 ...
- 学习红帽企业版RHEL 6.4的两问
(1)看了一晚上的RHEL 6.4,到现在也没分清楚服务器版和桌面版.都说两个版本是一个文件,那装上之后怎么判断这到底用的是服务器版还是桌面版?还有人说在安装过程中会要求选择,用虚拟机安装根本没看到有 ...
- SEO前端优化
精减代码 清除网页中一些冗余的代码,网上有这样的工具,可以辅助完成,如果需要的话,我们可以把代码中的注释去掉,甚至空行之类的也去掉,尽量的减少代码量,从而减小页面体积. CSS Sprites 通俗点 ...
- [GeekBand] 面向对象的设计模式(C++)(1)
一个模式描述了一个在我们周围不断重复发生的问题,以及该问题的解决方案的核心. 这样,你就能一次又一次 地使用该方案而不必做重复劳动. 0. 从面向对象谈起 底层思维与抽象思维: 底层思维要求程序员&q ...
- Poj 2840 Big Clock
1.Link: http://poj.org/problem?id=2840 2.Content: Big Clock Time Limit: 1000MS Memory Limit: 13107 ...
- 开发问题记录——AE开发提示80040111错误
System.runtime.interpServices.ComException(0X80040111): 80040111 ClassFactory无法供应请求的类(异常来自HRESULT:0X ...
- ToolStripStatusLabel设置时间自动更新
在使用委托设置界面上ToolStripStatusLabel类型的控件时间是,发现不能使用自定义的委托方法,在往上查找了一下发现不能使用involve来线程调用.因此只能使用原生委托方法. //代理p ...
- 修改zepto源代码,使支持wp8的ie10
注意:当前1.1.3版本的zepto,已经有模块来支持wp8 原先的zepto,通过__proto__赋值,来使dom继承到$.fn方法, 无奈IE11之前的IE10,IE9不支持这种写法, 所以我们 ...