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

http://www.lydsy.com/JudgeOnline/problem.php?id=1622

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

 1 #include <cstring>
 2 #include <cstdio>
 3
 4 const int N(1005);
 5 char name[N][N];
 6 int n,m,ans[N];
 7
 8 inline void Get(char *s)
 9 {
10     int len=strlen(s);
11     for(int i=0; i<n; ++i)
12     {
13         int k=0,L=strlen(name[i]);
14         for(int j=0; j<L; ++j)
15         {
16             if((name[i][j]-s[k]==32)||name[i][j]==s[k]||
17                (s[k]-name[i][j]==32)) k++;
18             if(k==len) { ans[i]++; break; }
19         }
20     }
21 }
22
23 int Presist()
24 {
25     scanf("%d%d",&n,&m);
26     for(int i=0; i<n; ++i)
27         scanf("%s",name[i]);
28     for(char s[N]; m--; )
29         scanf("%s",s),Get(s);
30     for(int i=0; i<n; ++i)
31         printf("%d\n",ans[i]);
32     return 0;
33 }
34
35 int Aptal=Presist();
36 int main(int argc,char**argv){;}
时间: 2024-08-03 14:38:19

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

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

模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; const int N=1005; int n,m,s1,s2,ans[N]; struct qwe { int len; char s[N]; }c[N],p[N]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<

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

1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 370  Solved: 184[Submit][Status][Discuss] Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串,  约翰有一张“能量字符串表”,上面有M(1≤M≤100)个代表能量的字符串.每个字符串由不超过3

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

bzoj1622[Usaco2008 Open]Word Power 名字的能量 题意: n个名字,m个能量字符串,每个名字的能量为其中含有能量字符串的种数(含有指有一个不连续子串与能量字符串相等),问每个名字的能量.n≤1000,m≤100. 题解: 暴力可过(似乎数据弱). 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cctype> 5 #

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

描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1622 给出多个文本串和模式串,求每个文本串中有多少模式串. 分析 直接暴力... 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn=1000+5,maxm=100+5,maxl=30+5; 5 int n,m; 6 int t[maxn][maxn],p[maxm][maxl]; 7 char c; 8

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

P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of his N (1 <= N <= 1000) cows. Each name is a string with no more than 1000 characters, all of which are non-blank. He has created a set of M (1 <= M

2015.05.15,外语,学习笔记-《Word Power Made Easy》 01 “如何讨论人格特点”

2015.03.17,外语,读书笔记-<Word Power Made Easy> 01 “如何讨论人格特点”学习笔记 SESSIONS 1 本来这些章节都是在一两年前学习的,现在趁给友人送书的机会,重新做一次笔记,也再次复习一遍. 蓝色字体仍然是注释,粗体主要是标题和要背诵的单词.红色的部分是自己的心得.我比较关注发音,所以除非是非常简单和直白的发音,我一般会查询词典得到准确的读音音标,并放上来. TEASER PREVIEW (Teaser 片头,预告片,玩笑 Teaser trailer

bzoj1622 / P2908 [USACO08OPEN]文字的力量Word Power

P2908 [USACO08OPEN]文字的力量Word Power 第一眼:AC自动机(大雾) 直接暴力枚举即可. 用<cctype>的函数较方便(还挺快) $isalpha(a)$:$a$是否是字母 $tolower(a)$:$a$把a转成小写 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cctype> 5 #define re register

[BZOJ] 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛

1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1312  Solved: 736[Submit][Status][Discuss] Description 奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走,试图找到整块草地中最美味的牧草.Farmer John在某个时刻看见贝茜在位置 (R1, C1),恰好T

2015.05.04,外语,读书笔记-《Word Power Made Easy》 14 “如何谈论日常现象” SESSION 41

1. people are the craziest animals bovine(['b?uvain] adj. (似)牛的, 迟钝的),像牛一样placid(['plæsid] adj. 安静的, 平和的),stolid.patient.unexcitable,来自描绘ox或cow的拉丁词语boivs,加上后缀-ine(like,similar to,characteristic of).称某人bovine并不是赞扬他,这个词比phlegmatic([fleg'mætik] adj. 冷静的