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 <= 100) 'good' strings (no

longer than 30 characters and fully non-blank). If the sequence letters of a cow's name contains the letters of a 'good' string in the correct order as a subsequence (i.e., not necessarily all next to each other), the cow's name gets 1 quality point.

All strings is case-insensitive, i.e., capital letters and lower case letters are considered equivalent. For example, the name 'Bessie' contains the letters of 'Be', 'sI', 'EE', and 'Es' in the correct order, but not 'is' or 'eB'. Help Farmer John determine the number of quality points in each of his cow's names.

约翰想要计算他那N(l < =N <= 1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字 符构成,没有一个名字是空字体串.

约翰有一张“能量字符串表”,上面有M(1 < =M < =100)个代表能量的字符串.每个字符串 由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名 字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不 一定一个紧接着一个).

所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be” “si” “EE”以及“Es”等等字符串,但不蕴含“Ls”或“eB” .请帮约翰计算他的奶牛的名字 的能量.

输入输出格式

输入格式:

  • Line 1: Two space-separated integers: N and M

  • Lines 2..N+1: Line i+1 contains a string that is the name of the ith cow

  • Lines N+2..N+M+1: Line N+i+1 contains the ith good string

输出格式:

  • Lines 1..N+1: Line i+1 contains the number of quality points of the ith name

输入输出样例

输入样例#1: 复制

5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
输出样例#1: 复制

1
1
2
0
1

说明

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

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

模拟

挨个字符枚举判断

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1010
using namespace std;
char ch[N][N],s[N];
int n,m,k,l,len,ans[N];
int read()
{
    ,f=; char ch=getchar();
    ;ch=getchar();}
    +ch-',ch=getchar();
    return x*f;
}
int work(char *s)
{
    len=strlen(s);
    ;i<=n;i++)
    {
        k=;l=strlen(ch[i]);
        ;j<l;j++)
        {
            ||s[k]-ch[i][j]==) k++;
            if(k==len){ans[i]++;break;}
        }
    }
}
int main()
{
    n=read(),m=read();
    ;i<=n;i++)
     cin>>ch[i];
    ;i<=m;i++)
     cin>>s,work(s);
    ;i<=n;i++)
     printf("%d\n",ans[i]);
    ;
}

洛谷——P2908 [USACO08OPEN]文字的力量Word Power的更多相关文章

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

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

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

    题目描述 Farmer John wants to evaluate the quality of the names of his N (1 <= N <= 1000) cows. Ea ...

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

    P2908 [USACO08OPEN]文字的力量Word Power 第一眼:AC自动机(大雾) 直接暴力枚举即可. 用<cctype>的函数较方便(还挺快) $isalpha(a)$:$ ...

  4. 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm

    P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...

  5. 洛谷——P2910 [USACO08OPEN]寻宝之路Clear And Present Danger

    P2910 [USACO08OPEN]寻宝之路Clear And Present Danger 题目描述 Farmer John is on a boat seeking fabled treasur ...

  6. 洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集

    题目: https://www.luogu.org/problemnew/show/P2906 题解: 垃圾水题 #include<cstdio> #include<algorith ...

  7. 洛谷 P2909 [USACO08OPEN]牛的车Cow Cars

    传送门 题目大意: m个车道. 如果第i头牛前面有k头牛,那么这头牛的最大速度会 变为原本的速度-k*D,如果速度小于l这头牛就不能行驶. 题解:贪心 让初始速度小的牛在前面 代码: #include ...

  8. 洛谷P1435 回文字串(dp)

    题意 题目链接 回文词是一种对称的字符串.任意给定一个字符串,通过插入若干字符,都可以变成回文词.此题的任务是,求出将给定字符串变成回文词所需要插入的最少字符数. 比如 “Ab3bd”插入2个字符后可 ...

  9. 洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm

    题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < ...

随机推荐

  1. 2017 济南综合班 Day 1

    送分题(songfen) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK喜欢干一些有挑战的事,比如说求区间最大子段和.它知道这个题目有O(n)的做法.于 ...

  2. hdu 3689 Infinite monkey theorem

    Infinite monkey theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  3. Python代码解决RenderView窗口not found问题

    源 起 Error:setParent: Object 'renderView' not found 这是一个在工作中很常见的问题,以前做特效的时候有10%的概率会碰到,多发生在打开其他组交接来的Ma ...

  4. 「6月雅礼集训 2017 Day5」吃干饭

    [题目大意] 询问[L,R]中选若干个数异或起来得到的答案集合大小.多组数据. 对于50%的数据,$R - L \leq 10^4$ 对于100%的数据,$R - L \leq 10^{18}, T ...

  5. bzoj 1296 DP

    对于每一行做DP预处理,w[i][j]代表这一行前i个刷j次的最大价值,那么w[i][j]=max(w[i][j],w[k][j-1]+sum[k+1][i]),sum[i][j]为i-j段刷一次最多 ...

  6. 使用BackgroundWorker

    1,WPF应用程序为单线程模型(STAThread),所有UI控件都是主线程创建的,只有主线程能操作UI元素的显示. 2,其他工作线程要维护UI控件的显示,需调用主线程的Dispather,执行Inv ...

  7. Eclipse svn 忽略文件夹/ svn 设置不同步

    Eclipse 开发中我们经常用到SVN插件, 但是对于某些文件的缓存来说, 我们只要有操作缓存便会保存一次, 每次提交很是麻烦, 小编这里教你一种不同步某个文件夹的方法 工具/原料 MyEclips ...

  8. 【数位dp入门】【HDU2089】62

    为了我的点歪的技能树…… 所以开始补一些sb的东西…… #include<bits/stdc++.h> typedef long long ll; using namespace std; ...

  9. java8新特性视频、spring4.0视频讲解,javaee基础知识讲解等网址汇总

    1.http://ke.atguigu.com/     海量视频首页 2.http://ke.atguigu.com/course/56    java8新特性学习地址

  10. Memcached内存缓存技术

    Memcached是什么,有什么作用? Memcached是一个开源的.高性能的内存缓存软件,从名称上看Mem就是内存的意思,而Cache就是缓存的意思. Memcached通过在事先规划好的内存空间 ...