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 这个题的核心 ...
随机推荐
- xmlns:xsi ——是指xml文件遵守xml规范,xsi全名:xml schema instance
http://blog.sina.com.cn/s/blog_4b6f8d150100nx3e.html http://blog.csdn.net/iaiti/article/details/4226 ...
- HDU2579
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 使用数字签名实现数据库记录防篡改(Java实现)
本文大纲 一.提出问题 二.数字签名 三.实现步骤 四.参考代码 五.后记 六.参考资料 一.提出问题 最近在做一个项目,需要对一个现成的产品的数据库进行操作,增加额外的功能.为此,需要对该产品对数据 ...
- XCode中设置字体大小
XCode中设置字体大小 1)打开Preferences,快捷键是“Command + ,”(注意,是三个键,按住command键,然后再快速地按“+”和“,”两个键即可) 2)选择“Fonts &a ...
- Android几行代码实现实时监听微信聊天
实现效果: 实时监听当前聊天页面的最新一条消息,如图: 实现原理: 同样是利用AccessibilityService辅助服务,关于这个服务类还不了解的同学可以先看下我上一篇关于 ...
- atom编辑器快捷键
挑来挑去,还是决定选择atom,做为我的编程编辑器. 下面是我总结的atom快捷键 //1.atomcmd+,; 设置cmd+h; 隐藏程序cmd+alt+h; 隐藏其他程序 //2.文件cmd+n; ...
- 每日一水之strcmp用法
strcmp函数 C/C++函数,比较两个字符串 设这两个字符串为str1,str2, 若str1==str2,则返回零: 若str1<str2,则返回负数: 若str1>str2,则返回 ...
- Exiting the Matrix: Introducing Metasploit's Hardware Bridge
Metasploit is an amazing tool. You can use it to maneuver through vast networks, pivoting through se ...
- How To Ask Questions The Smart Way 转
先查后问多思考莫做伸手党. 原文链接 译文链接
- 如何快速赚钱:Python爬虫
Python爬虫和毛爷爷的关系:Python是最简单最流行的开发语言,毛爷爷是最招人喜欢的人民币.如果你学会了Python爬虫,就可以挣更多的毛爷爷. 大家发现没有,实际上Python早已经火起来了, ...