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/C++将一个整型数组拼接成一个字符串
参考: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <stdio.h> #include <string.h> int ma ...
- Java泛型类定义,与泛型方法的定义使用
package com.srie.testjava; public class TestClassDefine<T, S extends T> { public static void m ...
- J.U.C并发框架
转载:http://itindex.net/detail/48869-j.u.c-%E6%A1%86%E6%9E%B6 J.U.C并发框架 作者:Doug Lea SUNY Oswego Oswego ...
- 项目实战(连载):基于Angular2+Mongodb+Node技术实现的多用户博客系统教程(2)
本章主要讲什么(一句话)? <项目实战:基于Angular2+Mongodb+Node技术实现的多用户博客系统教程(2)> -- 基于MongoDB的MyBlog数据库知识技术储备(上 ...
- 学习window系统下的注册表
一直不明白注册表是一个什么鬼,查了资料后大概明白了注册表到底有什么用,其实简单来说注册表就是一个存放系统.硬件.应用配置信息的数据ku.##### 一.注册表的来历在最早的视窗操作系统win3.x中, ...
- C#实现HttpUtility.UrlEncode输出大写字母
在c#中,HttpUtility.UrlEncode("www+mzwu+com")编码结果为www%2bmzwu%2bcom,在和Java开发的平台做对接的时候,对方用用url编 ...
- win10更新时遇到错误0x80070002的正确处理方法
win10更新Flash Player.或者在 “启用或关闭windows功能” 经常出现提示错误0x80070002,这要怎么解决呢?这里介绍下正确的错误代码0x80070002解决办法. 严肃提 ...
- 图片上传裁剪zyupload
图片上传控件用的是zyupload控件,使用过程中遇到了一些问题,特别记录下来 上图是目前的使用效果,这个控件我是用js代码动态添加出来的 HTML代码: <div class="wi ...
- Apache常见功能实战详解
Apache 是一款使用量排名第一的 web 服务器,LAMP 中的 A 指的就是它.由于其开源.稳定.安全等特性而被广泛使用.前边的一篇文章中已经记录过如何搭建 LAMP 架构,搭建仅是第一步,其中 ...
- js设计模式--迭代器模式
迭代器模式: 迭代器模式提供一种方法顺序访问一个聚合对象中各个元素,而又不需要暴露该方法中的内部表示.js中我们经常会封装一个each函数用来实现迭代器. 理解的意思:提供一个方法,去把对象的每一项按 ...