Hat’s Words HDU - 1247 字典树
题意:给出数个单词 输出单词 如果该单词 是由字典中的单词组成的
思路:字典树 先把全部建树 然后对于每一个单词进行分割,分别拿两半到字典树里面去找
小心RE!
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn=+;
struct Trie{
int ch[maxn][];
int size;
bool num[maxn];
void init(){
memset(ch,,sizeof(ch));
memset(num,,sizeof(num));
size=;
}
void insert(char*s){
int i=,rc=;
for( ;s[i]!='\0';i++){
int id=s[i]-'a';
if(ch[rc][id]==){
ch[rc][id]=size++;
}
rc=ch[rc][id];
}
num[rc]=;
}
bool find(char*s){
int i=,rc=;
for(;s[i]!='\0';i++){
int id=s[i]-'a';
if(ch[rc][id]==){
return ;
}
rc=ch[rc][id];
}
return num[rc];
} }trie;
char temp[][];
char s1[],s2[];
int main(){
int n=;
trie.init();
while(scanf("%s",temp[n])==){
//cout<<1<<endl;
n++;
trie.insert(temp[n-]);
}
for(int i=;i<n;i++){
int len=strlen(temp[i]);
for(int j=;j<len-;j++){
for(int k=;k<j;k++){
s1[k]=temp[i][k];
}
s1[j]='\0';
for(int k=j;k<len;k++)s2[k-j]=temp[i][k];
s2[len-j]='\0';
if(trie.find(s1)&&trie.find(s2)){
printf("%s\n",temp[i]);
break;
}
}
}
return ;
}
Hat’s Words HDU - 1247 字典树的更多相关文章
- hdu 1247 (字典树入门)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 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 2112(字典树+最短路)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2072(字典树模板,set,map均可做)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...
- Chip Factory HDU - 5536 字典树(删除节点|增加节点)
题意: t组样例,对于每一组样例第一行输入一个n,下面在输入n个数 你需要从这n个数里面找出来三个数(设为x,y,z),找出来(x+y)^z(同样也可以(y+z)^1)的最大值 ("^&qu ...
- hdu 1251 字典树的应用
这道题看了大神的模板,直接用字典树提交的会爆内存,用stl 里的map有简单有快 #include <iostream> #include <map> #include < ...
- hdu 2896 字典树解法
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> ...
- Repository HDU - 2846 字典树
题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...
随机推荐
- ASP.NET MVC5+EF6+EasyUI 后台管理系统-WebApi的用法与调试
1:ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-WebApi与Unity注入 使用Unity是为了使用我们后台的BLL和DAL层 2:ASP.NET MVC5+EF6+Easy ...
- 关于 HTTP GET/POST 请求参数长度最大值的一个理解误区(转载)
1. Get方法长度限制 Http Get方法提交的数据大小长度并没有限制,HTTP协议规范没有对URL长度进行限制.这个限制是特定的浏览器及服务器对它的限制.下面就是对各种浏览器和服务器的最大处理能 ...
- H5 15-交集选择器
15-交集选择器 我是段落 我是段落 我是段落 我是段落 我是段落 <!DOCTYPE html> <html lang="en"> <head> ...
- Mike and strings CodeForces - 798B (又水又坑)
题目链接 题意:英语很简单,自己取读吧. 思路: 既然n和i字符串的长度都很小,最大才50,那么就是只要能出答案就任意暴力瞎搞. 本人本着暴力瞎搞的初衷,写了又臭又长的200多行(代码框架占了50行) ...
- 02-安装linux系统
安装linux系统 需要准备的软件: 1.VMware-workstation-full-14.1.1.28517.exe 2.CentOS-6.5-x86_64-bin-DVD1.iso镜像文件 第 ...
- Linxu-chsh命令
chsh用于修改登陆后的shell,每个用户都有独立的shell. 以下是chsh命令的常用操作: 一.查看本机安装了哪些shell chsh -l 二.查看当前用户正在使用的Shell ...
- PAT 7-14 公路村村通
https://pintia.cn/problem-sets/1111189748004499456/problems/1111189831248850957 现有村落间道路的统计数据表中,列出了有可 ...
- js判断是否是微信浏览器以及重定向
async created () {//这个是判断是否是微信浏览器, let ua = navigator.userAgent.toLowerCase() if (ua.match(/MicroMes ...
- PreparedStatement 与 Statement 的区别
1. PreparedStatement 接口继承 Statement, PreparedStatement 实例包含已编译的 SQL 语句,所以其执行速度要快于 Statement 对象. 2.作为 ...
- springboot 如何操作redis
1.首先应该引入 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...