1622: [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 370 Solved: 184
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
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
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
题解:这道题显然可以暴力随便谢谢水过,但要是这样子的话就远远没有辣么好玩了,于是我再一次请出了萌萌哒线段树——
线段树存储每一个名字,然后连维护都不需要,直接实现查找在某某区间范围内最靠左的某个指定字母的位置,然后有了这个,就可以直接用后面的子串对前面的名字进行匹配即可,复杂度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 名字的能量的更多相关文章
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
题目 1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved ...
- 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...
- BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...
- bzoj 1622: [Usaco2008 Open]Word Power 名字的能量【模拟】
模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; ...
- [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 408 Solved: 19 ...
- bzoj1622 [Usaco2008 Open]Word Power 名字的能量
Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1 ...
- BZOJ_1622_[Usaco2008_Open]_Word_Power_名字的能量_(字符匹配_暴力)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1622 给出多个文本串和模式串,求每个文本串中有多少模式串. 分析 直接暴力... #inclu ...
- 洛谷——P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
- 洛谷 P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
随机推荐
- double减法不准确的那些事儿
CREATE TABLE `helei` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `num1` double DEFAULT NULL ...
- 列表视图(ListView)和ListActivity
ListView是手机系统中使用非常广泛的一种组件,它以垂直列表的形式显示所有列表项. 创建ListView有如下两种方式: 直接使用ListView进行创建. 让Activity继承ListActi ...
- 创建第一个Android应用程序 HelloWorld
按照博客的进程,今天应该进行程序编写啦,下面让我们开写一个简单的HelloWorld程序. 提示:这里对于如何使用Eclipse创建一个Android程序就不多讲啦,不会的同学可以去查阅相关文档. 程 ...
- Flex中escape/encodeURI/encodeURIComponent的区别
Flex中提供了三种转码函数,各有各的区别, escape,encodeURI,encodeURIComponent 这三个函数不仅在flex中有道运用在javascript中同样的含义 ,今天我仔细 ...
- 如何编译POCO
Poco C++库是: 一系列C++类库,类似Java类库,.Net框架,Apple的Cocoa; 侧重于互联网时代的网络应用程序 使用高效的,现代的标准ANSI/ISO C++,并基于STL 高可移 ...
- 有效的GOCsharpHelper1.0(源代码开放)
csharp编写界面,调用基于opencv的图像处理类库,是解决一类问题的优良方法.经过不懈研究,有最新进展: 一.目前情况和优点 位置在11.通过clr 架在c ...
- 我的小工具开源一下-PingTest
v博客前言 先交代下背景,最近我们项目组的网络真是太渣了,时常remote不了另外一个地方的机器,过个几分钟就断开连接,太烦躁了,严重影响工作心情...于是想着做个工具记录下每天的断开remote连接 ...
- 微信小程序教程(第四篇)
小程序开发基本框架及其限制与优化 开发基本框架(MINA框架) └─ Project-folder/ ·································· 项目所在目录 ├─ page ...
- Python自然语言处理学习笔记之评价(evaluationd)
对模型的评价是在test set上进行的,本文首先介绍测试集应该满足的特征,然后介绍四种评价方法. 一.测试集的选择 1.首先,测试集必须是严格独立于训练集的,否则评价结果一定很高,但是虚高,不适用于 ...
- spring配置文件头部xmlns配置精髓
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...