1622: [Usaco2008 Open]Word Power 名字的能量

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 370  Solved: 184
[Submit][Status][Discuss]

Description

    约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串,  约翰有一张“能量字符串表”,上面有M(1≤M≤100)个代表能量的字符串.每个字符串由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不一定一个紧接着一个).
    所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be”
“sI”“EE”以及“Es”等等字符串,但不蕴含“lS”或“eB”.请帮约翰计算他的奶牛的名字的能量.

Input

    第1行输入两个整数N和M,之后N行每行输入一个奶牛的名字,之后M行每行输入一个能量字符串.

Output

 
    一共N行,每行一个整数,依次表示一个名字的能量.

Sample Input

5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont

INPUT DETAILS:

There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".

Sample Output

1
1
2
0
1

OUTPUT DETAILS:

"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".

HINT

 

Source

Silver

题解:这道题显然可以暴力随便谢谢水过,但要是这样子的话就远远没有辣么好玩了,于是我再一次请出了萌萌哒线段树——

线段树存储每一个名字,然后连维护都不需要,直接实现查找在某某区间范围内最靠左的某个指定字母的位置,然后有了这个,就可以直接用后面的子串对前面的名字进行匹配即可,复杂度O(NMLlogM)(居然还是2988 ms水过去了,好开心)

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n,ans:longint;
ss:ansistring;
b,c:array[..] of ansistring;
a:array[..,..] of longint;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
function max(x,y:longint):longint;inline;
begin
if x>y then max:=x else max:=y;
end;
procedure built(z,x,y:longint);
var i:longint;
begin
if (x=y) then
a[z,ord(ss[x])-]:=
else
begin
built(z*,x,(x+y) div );
built(z*+,(x+y) div +,y);
for i:= to do a[z,i]:=a[z*,i]+a[z*+,i]
end;
end;
function approach(z,x,y,l,r,t:longint):longint;
var a1:longint;
begin
if l>r then exit();
if a[z,t]= then exit();
if x=y then exit(x);
a1:=approach(z*,x,(x+y) div ,l,min(r,(x+y) div ),t);
if a1<> then exit(a1);
exit(approach(z*+,(x+y) div +,y,max(l,(x+y) div +),r,t));
end; begin
readln(n,m);
for i:= to n do
begin
readln(b[i]);
b[i]:=upcase(b[i]);
end;
for i:= to m do
begin
readln(c[I]);
c[i]:=upcase(c[i]);
end;
for i:= to n do
begin
ss:=b[i];
fillchar(a,sizeof(a),);
built(,,length(ss));
ans:=;
for j:= to m do
begin
l:=;
for k:= to length(c[j]) do
begin
l:=approach(,,length(ss),l+,length(ss),ord(c[j][k])-);
if l= then break;
end;
if l<> then inc(ans);
end;
writeln(ans);
end;
end.

1622: [Usaco2008 Open]Word Power 名字的能量的更多相关文章

  1. BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量

    题目 1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 349  Solved ...

  2. 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...

  3. BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量

    http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description     约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...

  4. bzoj 1622: [Usaco2008 Open]Word Power 名字的能量【模拟】

    模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; ...

  5. [Usaco2008 Open]Word Power 名字的能量

    1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 408  Solved: 19 ...

  6. bzoj1622 [Usaco2008 Open]Word Power 名字的能量

    Description     约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串,  约翰有一张“能量字符串表”,上面有M(1 ...

  7. BZOJ_1622_[Usaco2008_Open]_Word_Power_名字的能量_(字符匹配_暴力)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1622 给出多个文本串和模式串,求每个文本串中有多少模式串. 分析 直接暴力... #inclu ...

  8. 洛谷——P2908 [USACO08OPEN]文字的力量Word Power

    P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...

  9. 洛谷 P2908 [USACO08OPEN]文字的力量Word Power

    P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...

随机推荐

  1. 使用AIR进行移动APP开发常见功能和问题(上)

    1.  获取最近联系人 思路:侦听Geolocation的update事件,获取经度和纬度信息,再把坐标信息上传至服务器,服务器比较坐标信息算出距离,返回最近位置的若干个人. update时间在2种情 ...

  2. SVG六基本元素

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Activity生命周期完全解析

    **转载请注明出处:http://www.cnblogs.com/landptf/p/6309108.html** 生命周期是个老生常谈的问题了,今天做个汇总,全当是记个笔记,以后查找起来方便一些.下 ...

  4. JS日期时间加减实现

    首先,上代码 var diffDate = function(date, diff) { return new Date( Date.UTC( date.getUTCFullYear(), date. ...

  5. 用php进行md5解密的源码,亲测可用

    <?php $md5 = "c1c95b382230eb9e27a60c4baceb5f2e"; $uid = "hhp-ImZRY"; $token = ...

  6. Introduce: IEPI.BIATranscribe 图像表格拓写工具

    应用场合 数据表格是学术.文案工作中常用的表述形式.我们经常需要从第三方获取所需的数据.有些时候这些数据并非以可直接编辑的形式(如电子表格文档),而是以打印件或者扫描件的形式提供.假如需要对数据进行进 ...

  7. C# 数组、ArrayList、List、Dictionary的用法与区别

    前言 在工作中经常遇到C#数组.ArrayList.List.Dictionary存取数据,但是该选择哪种类型进行存储数据,对于初学者的我一直不知道该怎么取舍.于是抽空好好看了下他们的用法和比较,在这 ...

  8. [python]Python2编码问题

    以下内容说的都是 python 2.x 版本 简介 基本概念 Python "帮"你做的事情 推荐姿势 基本概念 我们看到的输入输出都是'字符'(characters),计算机(程 ...

  9. Windows 10 IoT Serials 5 - 如何为树莓派应用程序添加语音识别与交互功能

    都说语音是人机交互的重要手段,虽然个人觉得在大庭广众之下,对着手机发号施令会显得有些尴尬.但是在资源受限的物联网应用场景下(无法外接鼠标键盘显示器),如果能够通过语音来控制设备,与设备进行交互,那还是 ...

  10. asp.net权限认证:Windows认证

    asp.net权限认证系列 asp.net权限认证:Forms认证 asp.net权限认证:HTTP基本认证(http basic) asp.net权限认证:Windows认证 asp.net权限认证 ...