博客
关于我
Hat’s Words(字典树)
阅读量:620 次
发布时间:2019-03-13

本文共 2202 字,大约阅读时间需要 7 分钟。

Hat’s Words

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 11314    Accepted Submission(s): 4041

Problem Description
A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.
 

 

Input
Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
Only one case.
 

 

Output
Your output should contain all the hat’s words, one per line, in alphabetical order.
 

 

Sample Input
aahathathatwordhzieeword
 

 

Sample Output
ahathatword
 
题解:判断单词是否是由两个单词合并得到,加了个val判断是否为一个完整的单词;本来还以为是只与hat结合呐,神经的只减去hat,谁知道,自己想错了。。。是两个单词的结合;
代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 #define mem(x,y) memset(x,y,sizeof(x)) 8 const int INF=0x3f3f3f3f; 9 const double PI=acos(-1.0);10 const int MAXN=50010;11 int ch[MAXN][30],word[MAXN],val[MAXN];12 char dt[50010][110];13 int sz;14 void initial(){15 sz=1;16 mem(ch[0],0);mem(word,0);mem(val,0);17 }18 void join(char *s){19 int len=strlen(s),k=0,j;20 for(int i=0;i

 

#include
#include
#include
#include
#include
using namespace std;typedef long long LL;#define mem(x,y) memset(x,y,sizeof(x))#define SI(x) scanf("%d",&x)#define PI(x) printf("%d",x)#define P_ printf(" ")const int INF=0x3f3f3f3f;const int MAXN=1000010;//要开的足够大 int ch[MAXN][30];int word[MAXN];char str[50010][110];int val[MAXN]; int sz;int N;char l[110],r[110];void insert(char *s){ int k=0,j; for(int i=0;s[i];i++){ j=s[i]-'a'; if(!ch[k][j]){ mem(ch[sz],0); ch[k][j]=sz++; } k=ch[k][j]; word[k]++; } val[k]=1;}bool find(char *s){ int k=0,j; for(int i=0;s[i];i++){ j=s[i]-'a'; k=ch[k][j]; if(!word[k])return false; } if(val[k]!=1)return false; return true;}int main(){ int tp=0; sz=1; mem(ch[0],0);mem(val,0);mem(word,0); while(~scanf("%s",str[tp]))insert(str[tp++]);// printf("%d\n",tp); for(int i=0;i

  

转载地址:http://aueaz.baihongyu.com/

你可能感兴趣的文章
Mysql学习总结(22)——Mysql数据库中制作千万级测试表
查看>>
Mysql学习总结(23)——MySQL统计函数和分组查询
查看>>
Mysql学习总结(24)——MySQL多表查询合并结果和内连接查询
查看>>
Mysql学习总结(25)——MySQL外连接查询
查看>>
Mysql学习总结(26)——MySQL子查询
查看>>
Mysql学习总结(27)——Mysql数据库字符串函数
查看>>
Mysql学习总结(28)——MySQL建表规范与常见问题
查看>>
Mysql学习总结(29)——MySQL中CHAR和VARCHAR
查看>>
Mysql学习总结(2)——Mysql超详细Window安装教程
查看>>
Mysql学习总结(30)——MySQL 索引详解大全
查看>>
Mysql学习总结(31)——MySql使用建议,尽量避免这些问题
查看>>
Mysql学习总结(32)——MySQL分页技术详解
查看>>
Mysql学习总结(33)——阿里云centos配置MySQL主从复制
查看>>
Mysql学习总结(34)——Mysql 彻底解决中文乱码的问题
查看>>
Mysql学习总结(35)——Mysql两千万数据优化及迁移
查看>>
Mysql学习总结(36)——Mysql查询优化
查看>>
Mysql学习总结(37)——Mysql Limit 分页查询优化
查看>>
Mysql学习总结(38)——21条MySql性能优化经验
查看>>
Mysql学习总结(39)——49条MySql语句优化技巧
查看>>
Mysql学习总结(3)——MySql语句大全:创建、授权、查询、修改等
查看>>