首页 技术 正文
技术 2022年11月14日
0 收藏 943 点赞 3,094 浏览 2099 个字

题目


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

Time Limit: 5 Sec  Memory Limit: 64 MB

Submit: 349  Solved: 168

[Submit][Status]

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".


题解


暴力就可以了。


代码


/*Author:WNJXYK*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
using namespace std;#define LL long long
#define Inf 2147483647
#define InfL 10000000000LLinline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
inline int remin(int a,int b){if (a<b) return a;return b;}
inline int remax(int a,int b){if (a>b) return a;return b;}
inline LL remin(LL a,LL b){if (a<b) return a;return b;}
inline LL remax(LL a,LL b){if (a>b) return a;return b;}string name[1001];
string power[101];
int ans[1001];
int n,m;
inline char upcase(char x){
if ('a'<=x && x<='z') return x-'a'+'A';
return x;
}
inline int judge(int x,int y){
int lx=power[x].length()-1,ly=name[y].length()-1;
for (int i=0;i<=ly-lx;i++){
bool flag=true;
int now=i;
if (upcase(name[y][i])==upcase(power[x][0]))
for (int j=1;j<=lx;j++){
now++;
while(now<=ly && upcase(power[x][j])!=upcase(name[y][now])) now++;
if (now>ly) {
flag=false;
break;
}
}
else
continue;
if (flag) return 1;
}
return 0;
}
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) cin>>name[i];
for (int j=1;j<=m;j++) cin>>power[j];
for (int i=1;i<=m;i++){
for (int j=1;j<=n;j++){
ans[j]+=judge(i,j);
}
}
for (int i=1;i<=n;i++)printf("%d\n",ans[i]);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,355
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,138
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848