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都放字典树 ...
随机推荐
- Beta阶段团队成员贡献分分配规则
Beta阶段团队成员贡献分分配规则 Alpha阶段贡献分分配有些负责,在这里进行一些修改: 对任务完成得分部分进行了简化 对发现bug的惩罚措施进行了修改 移除了优化得分,不鼓励修改他人代码 移除了帮 ...
- [LeetCode] Rank Scores -- 数据库知识(mysql)
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- codeforces#687 B. Remainders Game
题意:给出n个数,和一个数p,问你在知道 x%ai 的情况下,能不能确定x%p的值 结论:当n个数的最小公倍数是p的倍数时,可以确定 代码: #include <bits/stdc++.h&g ...
- 动态规划-LCS最长公共子序列
#include<iostream> #include<cstdio> #include<cstring> #include<string> using ...
- Python学习第十二篇——切片的使用
Python中使用函数切片可以创建副本,保留原本.现在给出如下代码 magicians_list = ['mole','jack','lucy'] new_lists = [] def make_gr ...
- iOS蓝牙开发之iBeacon技术
iBeacon组成信息: 1 .UUID(universally unique identifier):一个128位的唯一标识一个或多个Beacon基站为特定类型或特定的组织. 2. Major:一个 ...
- 会议室预订系统(meeting room booking system)
一.mrbs mrbs:(meeting room booking system) 二.效果 三.models from django.db import models # Create your ...
- Linux的LiveCd与CD、DVD版
https://blog.csdn.net/sun_168/article/details/6744401
- asp.net core前后端分离
陆陆续续的看了两个礼拜的前端知识,把vue+vue-router+axios的知识撸了一遍,本来想加个element-ui来实现一下前后端分离,实施的时候却遇到了很多的坑.我本身不在一个软件开发公司上 ...
- C#复习笔记(4)--C#3:革新写代码的方式(Lambda表达式和表达式树)
Lambda表达式和表达式树 先放一张委托转换的进化图 看一看到lambda简化了委托的使用. lambda可以隐式的转换成委托或者表达式树.转换成委托的话如下面的代码: Func<string ...