字典树 (HDU 2072)
you are my friend
#
Sample Output
4 题目分析 : 这题用 map 写时很方便的,为了联系字典树,用字典树写了一发。 代码示例 :
#define ll long long
const int maxn = 1e5+5;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f; char s[maxn], f[100];
struct node
{
int next[26];
int val;
}t[maxn];
int rt;
int ans = 0, k; void build(){
int u = 0, v; for(int i = 0; i < k; i++){
v = f[i] - 'a';
if (!t[u].next[v]){
t[u].next[v] = rt++;
}
u = t[u].next[v];
}
t[u].val++;
if (t[u].val == 1) ans++;
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout); while(gets(s+1)){
if (s[1] == '#') break; int len = strlen(s+1);
memset(t, 0, sizeof(t));
rt = 1;
s[len+1] = ' ';
k = 0; ans = 0;
for(int i = 1; i <= len+1; i++){
if (s[i] != ' '){
f[k++] = s[i];
}
else {
if (k != 0)build();
k = 0;
}
}
cout << ans << endl;
}
return 0;
}
字典树 (HDU 2072)的更多相关文章
- 字典树 HDU 1251 统计难题
;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace st ...
- 字典树 HDU 1075 What Are You Talking About
http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}
- 字典树&&01字典树专题&&对字典树的理解
对于字典树和01字典树的一点理解: 首先,字典树建树的过程就是按照每个数的前缀来的,如果你要存储一个全小写字母字符串,那么这个树每一个节点最多26个节点,这样的话,如果要找特定的单词的话,按照建树的方 ...
- HDU 2072 - 单词数 - [(有点小坑的)字典树模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072 Problem Descriptionlily的好朋友xiaoou333最近很空,他想了一件没有 ...
- hdu 2072(字典树模板,set,map均可做)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 5687 字典树插入查找删除
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5687 2016百度之星资格赛C题,直接套用字典树,顺便巩固了一下自己对字典树的理解 #include< ...
- HDU 5384 字典树、AC自动机
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5384 用字典树.AC自动机两种做法都可以做 #include<stdio.h> #includ ...
- HDU 4287 Intelligent IME(字典树数组版)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- notepad2正则表达式替换字符串
例子: 1-385-463-3226替换成13854633226 Ctrl+H开启替换,选中'regular expression search'或者正则表达式: 上面输入:1-(.*)-(.*)-( ...
- 51nod 1380"夹克老爷的逢三抽一"(贪心+set)
传送门 •参考资料 [1]:51Nod-1380-夹克老爷的逢三抽一 •题意 从长度为 n 的数组中抽取 $\frac{n}{3}$ 个不相邻的值使得加和最大(首尾也不能同时取) •题解 贪心选择当前 ...
- H3C DR和BDR选举
- python NameError: name 'raw_input' is not defined
错误:NameError: name 'raw_input' is not defined 原因出在raw_input ,python3.0版本后用input替换了raw_input 话说回来,学习p ...
- P1068 压缩技术
题目描述 设某汉字由N × N的0和1的点阵图案组成. 我们依照以下规则生成压缩码.连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从左到右,由上至下.第一个数表示连续有几个0,第二 ...
- 2018-8-10-如何在-UWP-使用-wpf-的-Trigger-
title author date CreateTime categories 如何在 UWP 使用 wpf 的 Trigger lindexi 2018-08-10 19:16:51 +0800 2 ...
- thinter图形开发界面
tkinter编程步骤 导入Tkinter 创建控件 import thinter 创建主窗口 #win = tkinter.Tk() 设置标题 win.title("xiaoxin&quo ...
- 牛客小白月赛15A 斑羚飞渡
链接:https://ac.nowcoder.com/acm/contest/917/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言262144K 64b ...
- vc得到屏幕的当前分辨率方法
vc得到屏幕的当前分辨率方法:1.Windows API调用int width = GetSystemMetrics ( SM_CXSCREEN ); int height= GetSystemMet ...
- 研发环境容器化实施过程(docker + docker-compose + jenkins)
目录 背景介绍 改造思路 容器构建 基础准备 中间件容器 外部依赖容器 业务应用容器 容器整合 自动构建容器 Maven相关 非Maven项目 总结 背景介绍 目前公司内部系统(代号GMS)研发团队, ...