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连接oracle的问题及方法总结
.net连oracle数据库的两个方法介绍1. 安装oracle客户端,连接oracle 需要在客户端%oracle_client_home%network/admin/配置tnsnames.ora, ...
- IOS离线教程下载与Dash的使用
都知道,苹果官网的IOS Developer Library是开发者最喜欢用的知识仓库,但由于有时打开它实在太慢了! 但是,我们可以手动下载离线版的!离线的文档,在这里,叫做DocSet,意指文档集合 ...
- 弹性布局学习-详解 justify-content(三)
弹性布局学习-详解 justify-content(三)
- FireFox不支持InnerText的解决方法
innerText和InnerHTML是非常实用的一个属性,然而在FireFox中不支持此属性,可能是因为考虑到网页的安全性.这样一来为开发者带来了不少麻烦.FireFox中也提供了另外一个属性inn ...
- Spark Streaming揭秘 Day12 数据安全容错(Executor篇)
Spark Streaming揭秘 Day12 数据安全容错(Executor篇) 今天,让我们研究下SparkStreaming在Executor端的数据安全及容错机制. 在SparkStreami ...
- python的浅拷贝和深拷贝
python对象有两种拷贝的形式:浅拷贝和深拷贝. 在<python核心编程>中看到对这两种拷贝的分析,觉得十分收益,所以记录在此. id()方法:id()方法可以查看某个对象的ID,类似 ...
- Python学习_从文件读取数据和保存数据
运用Python中的内置函数open()与文件进行交互 在HeadFirstPython网站中下载所有文件,解压后以chapter 3中的“sketch.txt”为例: 新建IDLE会话,首先导入os ...
- 程序使用嵌套的for循环找出2〜100中的素数
#import <Foundation/Foundation.h> int main () { /* local variable definition */ int i, j; ; i& ...
- WP8.1和Win8.1的不同之处
本文仅是个人见解,如有不足或错误之处欢迎批评指正~ 1.Toast: 创建Toast代码差不多但实现机制及管理上不一样 2.ApplicationData: WP8.1多了一个LocalCacheFo ...
- C++ 字符串各种处理
要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...