1819: [JSOI]Word Query电子字典
1819: [JSOI]Word Query电子字典
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 729 Solved: 238
[Submit][Status]
Description
Input
Output
Sample Input
abcd
abcde
aabc
abced
abcd
abc
abcdd
Sample Output
2
3
HINT
abcd在单词表中出现过;abc与单词abcd、aabc的编辑距离都是1;abcdd与单词abcd、abcde、abced的编辑距离都是1。
Source
题解:这道题目里面的编辑距离为1,也就是三种最基本的情况,而且对于字典树而言都不难操作,所以直接乱搞搞就是啦(只要你会字典树)
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
ex:longint;
next:array['A'..'Z'] of point;
chi,bro:point;
ct:char;
end;
var
i,j,k,l,m,n,TP:longint;
head,p,p1:point;
s1:ansistring;
function getpoint:point;inline;
var p:point;c1:char;
begin
new(p);
p^.ex:=;p^.chi:=nil;
p^.bro:=nil;
for c1:='A' to 'Z' do p^.next[c1]:=nil;
exit(p);
end;
procedure add(p:point;c1:char);inline;
begin
if p^.next[c1]<>nil then exit;
p^.next[c1]:=getpoint;
p^.next[c1]^.ct:=c1;
p^.next[c1]^.bro:=p^.chi;
p^.chi:=p^.next[c1];
end;
procedure add(s1:ansistring);
var
p:point;i:longint;
begin
p:=head;
for i:= to length(s1) do
begin
add(p,s1[i]);
p:=p^.next[s1[i]];
end;
p^.ex:=;
end;
function exist(head:point;s1:ansistring;x:longint):boolean;inline;
var p:point;i:longint;
begin
p:=head;
for i:= to length(s1) do
begin
if p^.next[s1[i]]=nil then exit(false);
p:=p^.next[s1[i]];
end;
if x= then exit(not(p^.ex=));
if (p^.ex>) and (p^.ex<>tp) then
begin
p^.ex:=tp;
exit(true)
end
else exit(false);
end;
function more(s1:ansistring):longint;
var
p:point;i,j,k,l:longint;
begin
inc(tp);
p:=head;l:=;
for i:= to length(s1) do
begin
if exist(p,copy(s1,i+,length(s1)-i),) then inc(l);
if p^.next[s1[i]]=nil then exit(l);
p:=p^.next[s1[i]];
end;
exit(l);
end;
function just(s1:ansistring):longint;
var p,P1:point;i,j,k,l:longint;
begin
inc(tp);
p:=head;l:=;
for i:= to length(s1)- do
begin
p1:=p^.chi;
while p1<>nil do
begin
if exist(p1,copy(s1,i+,length(s1)-i),) then inc(l);
p1:=p1^.bro;
end;
if p^.next[s1[i]]=nil then exit(l);
p:=p^.next[s1[i]];
end;
if p^.chi=nil then exit(l);
p1:=p^.chi;
while p1<>nil do
begin
if (p1^.ex>) and (p1^.ex<>tp) then inc(l);
p1:=p1^.bro;
end;
exit(l);
end;
function less(s1:ansistring):longint;
var p,p1:point;i,j,k,l:longint;
begin
inc(tp);
p:=head;l:=;
for i:= to length(s1) do
begin
p1:=p^.chi;
while p1<>nil do
begin
if exist(p1,copy(s1,i,length(s1)-i+),) then inc(l);
p1:=p1^.bro;
end;
if p^.next[s1[i]]=nil then exit(l);
p:=p^.next[s1[i]];
end;
p1:=p^.chi;
while p1<>nil do
begin
if (p1^.ex>) and (p1^.ex<>tp) then inc(l);
p1:=p1^.bro;
end;
exit(l);
end;
begin readln(n,m);
head:=getpoint;
for i:= to n do
begin
readln(s1);
add(upcase(s1));
end;
tp:=;
for i:= to m do
begin
readln(s1);
s1:=upcase(s1);
if exist(head,s1,) then
begin
writeln(-);
continue;
end;
writeln(more(s1)+just(s1)+less(s1));
end; end.
1819: [JSOI]Word Query电子字典的更多相关文章
- 2786: [JSOI]Word Query电子字典
2786: [JSOI]Word Query电子字典 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3 Solved: 3[Submit][Statu ...
- BZOJ1819 [JSOI]Word Query电子字典 Trie
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1819 题意概括 字符串a与字符串b的编辑距离是指:允许对a或b串进行下列“编辑”操作,将a变为b或 ...
- [bzoj1819] [JSOI]Word Query电子字典
正解是trie树...在树上跳来跳去什么的 然而在企鹅qq那题的影响下我写了hash... 添加一个字母到一个串,就相当于另一个串删对应位置上的字母. 改变某个位置上的字母,就相当于两个字符串删掉同一 ...
- bzoj 1819: 电子字典 Trie
题目: Description 人们在英文字典中查找某个单词的时候可能不知道该单词的完整拼法,而只知道该单词的一个错误的近似拼法,这时人们可能陷入困境,为了查找一个单词而浪费大量的时间.带有模糊查询功 ...
- 洛谷P4407 [JSOI2009]电子字典
题目描述 人们在英文字典中查找某个单词的时候可能不知道该单词的完整拼法,而只知道该单词的一个错误的近似拼法,这时人们可能陷入困境,为了查找一个单词而浪费大量的时间.带有模糊查询功能的电子字典能够从一定 ...
- 改变word的语言字典
改变word的语言字典 上周末看论坛有人提出否有方法用代码改变word的语言字典,因为默认的语言会影响现用语言输入的拼写器和其他校对工具.我们的Spire.doc正好支持,正好闲来无事所以我用西班牙语 ...
- [LeetCode] Longest Word in Dictionary 字典中的最长单词
Given a list of strings words representing an English Dictionary, find the longest word in words tha ...
- 6.C语言文件操作之英语电子字典的实现,dos版
多的不说,直接上代码: 里面涉及的字典文件在这:这是传送门,下载下来以后把该文件放在工程目录下即可 #define _CRT_SECURE_NO_WARNINGS #include <stdio ...
- [leetcode]720. Longest Word in Dictionary字典中最长的单词
b.compareTo(a) 这个函数是比较两个值得大小,如果b比a大,那么返回1 如果小,那么返回-1,相等返回0 如果比较的是字符串,那么比较字典编纂顺序,b靠前返回-1,靠后返回1 这个题的核心 ...
随机推荐
- HTML URL
HTML 统一资源定位器(Uniform Resource Locators) URL 是一个网页地址. URL可以由字母组成,如"runoob.com",或互联网协议(IP)地址 ...
- MyBatis 的Mapper中有小于号的处理
<![CDATA[ select * from person t where t.birthday < #{birthday} ]]> 也可以进行转义: < < 小于号 ...
- SecureCRT 选择Courier New等其他字体.
http://justwinit.cn/post/5813/ 如何解决SecureCRT无法选择Courier New等其他字体最终解决办法:到C:\Windows\Fonts目录下,找到Courie ...
- 开源第三方登录组件OAuthLogin2.0 解析及开源地址
OAuthLogin2.0介绍地址: 博客地址:http://www.cnblogs.com/dazhuangtage/p/6306133.html Nuget地址:https://www.nuget ...
- [源代码] SailingEase .NET Resources Tool (.NET 多语言资源编辑器)
我在2016年10月发过一篇博客,介绍了我写过的一个多语言资源文件编辑器,并且做为免费软件发布给了出来. 陆续收到了一些朋友的反馈,有朋友很热心提了很多建议和关心的话,还有朋友发红包过来,让我很感动. ...
- puppet来管理文件和软件包
puppet来管理文件和软件包 1 exec的使用,可以运行shell命令 为配置文件添加配置,指示写了关键部分,其他配置省略没写 代码示例如下: [root@pup manifests]# cat ...
- Chrome 插件集锦
原文出处:CN_Simo 子曾曰:"工欲善其事,必先利其器.居是邦也."--语出<论语·卫灵公>:其后一百多年,荀子也在其<劝学>中倡言道:"吾尝 ...
- OpenCV 3.2正式发布啦
2016年12月23号OpenCV社区宣布了OpenCV3.2版本正式发布,这个是在OpenCV3.1版本发布一年以后再次升级.在3.2版本中有总数超过数千个的改进与修正,是OpenCV3.x系列中最 ...
- 用Spark学习矩阵分解推荐算法
在矩阵分解在协同过滤推荐算法中的应用中,我们对矩阵分解在推荐算法中的应用原理做了总结,这里我们就从实践的角度来用Spark学习矩阵分解推荐算法. 1. Spark推荐算法概述 在Spark MLlib ...
- 玩转 Ceph 的正确姿势
玩转 Ceph 的正确姿势 本文先介绍 Ceph, 然后会聊到一些正确使用 Ceph 的姿势:在集群规模小的时候,Ceph 怎么玩都没问题:但集群大了(到PB级别),这些准则可是保证集群健康运行的不二 ...