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 这个题的核心 ...
随机推荐
- C# 编写通用的JSON数据进行序列化和反序列化
注意事项:使用JSON系列化和反系列化,必须要添加引用System.Runtime.Serialization. 1.通用类代码如下: /// <summary> /// JSON序 ...
- JS效果的步骤
一.写JS效果的步骤 1.先实现布局 (XHTML+CSS2) 2.实现原理 (1)希望把某个元素移除你的视线: a. display:none; 显示为无,不占据空间 b. vi ...
- 如何给js动态创建的dom添加事件
delegate() 方法 实例 当点击鼠标时,隐藏或显示 p 元素: $("div").delegate("button","click" ...
- pureMVC简单示例及其原理讲解二(Model层)
本节将讲述Model层. Model层有VO和Mediator组成,非常简单,仅仅包含两个类:UserVO和UserProxy. UserVO中的构造器用于初始化用户的添加(通过email和密码),另 ...
- bootstrap 基本页面元素,代码,列表
bootstrap 基本页面元素,代码,列表 <!DOCTYPE html> <html> <head> <title></title> & ...
- Recurrent Neural Network系列2--利用Python,Theano实现RNN
作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...
- Android自定义控件系列(四)—底部菜单(下)
转载请注明出处:http://www.cnblogs.com/landptf/p/6290862.html 在app中经常会用到底部菜单的控件,每次都需要写好多代码,今天我们用到了前几篇博客里的控件来 ...
- 我的2016年终总结(PF项目框架设计心得分享 2.0rc)
在无数的日夜里,熬出了多少的黑眼圈,致勤勤恳恳工作的各位朋友与自己.每到了年末的时候总想写的什么,主要是为了回顾以往一年里到底做了什么,这便是年终总结的主要意义.在此我将要总结的是和我在技术层面上成长 ...
- 用虚拟 router 连通 subnet - 每天5分钟玩转 OpenStack(141)
Neutron Routing 服务提供跨 subnet 互联互通的能力.例如前面我们搭建了实验环境: cirros-vm1 172.16.100.3 vlan100 cirr ...
- 关于hashmap的底层实现
注:以下内容并非基于最新的jdk版本 q1:hashmap为什么叫hashmap? 答:hashmap基于hashtable(不是hashtable类)实现. q2:hashtable(不是hasht ...