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 这个题的核心 ...
随机推荐
- SQL server 定时自动执行SQL存储过程
当一个存储过程是为了生成报表,并且是周期性的,则不需要人工干预,由SQL作业定时自动执行些SQL存储过程即可. 本示例,假设已需要定时执行的存储过程为:Pr_test 工具/原料 SQL Server ...
- 字体图标 轻量级 Font Awesome
今天呢,来推荐一款请轻量级 字体图标框架.Font Awesome 用法与bootstrap相似 打开网址.download下载,然后打开取到这两个,下载点这里,这个博客弄的挺好的. 找到exampl ...
- SDWebImage源码解读之分类
第十一篇 前言 我们知道SDWebImageManager是用来管理图片下载的,但我们平时的开发更多的是使用UIImageView和UIButton这两个控件显示图片. 按照正常的想法,我们只需要在他 ...
- [C#]为微软ASP.NET官方教学视频增加字幕
前言 Microsoft Virtual Academy提供了学习ASP.NET的大量视频材料.(注1) 由于视频服务器位于海外,国内浏览速度并不理想,幸好官方提供了视频的下载地址以及英文字幕文件. ...
- linux pagecache与内存占用
实验环境 CentOS Linux release 7.3.1611 (Core) 3.10.0-514.6.1.el7.x86_64 一.概念介绍 linux系统中通常使用free命 ...
- fetch
1. 在order by fetch first中,所有的记录必须从磁盘取出来放入一个叫insert buffer的内部结构,然后进行排序,按照常识我们知道一般树排序的复杂度为O(nlogn), 最好 ...
- chrome浏览器360浏览器图片无法加载提示等待可用套接字问题
前端时间遇到chrome,360浏览器无法加载图片问题,提示等待可用的套接字 后来发现原因,原来是使用html5<video>标签时使用了默认的配置,默认情况下<video>标 ...
- Android jni 编程2(对基本类型一维整型数组的操作)
参考教程和这位博主的对一维数组的处理,主要包括以下三种类型: //传入一维数组,无返回值 public native void arrayEncode(int[] arr); //传一个一维数组和数组 ...
- Vuex 模块化与项目实例 (2.0)
Vuex 强调使用单一状态树,即在一个项目里只有一个 store,这个 store 集中管理了项目中所有的数据以及对数据的操作行为.但是这样带来的问题是 store 可能会非常臃肿庞大不易维护,所以就 ...
- 【转】IntelliJ IDEA2016.1 + maven 创建java web 项目
最近开始使用idea 来写java项目了,这个很流行,相比Eclipse方便了很多.功能多了,相对应的使用的复杂度也较高了,因为网上很多的使用和创建项目的简单教程,都是基于老版本的,每个新版本都有不一 ...