洛谷 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 <= 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<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int ans[1001];
char c[31],s[1001][1010];
bool judge(int pos,int j,int k){
    if(c[pos]>=‘A‘&&c[pos]<=‘Z‘)    c[pos]+=32;
    if(s[j][k]>=‘A‘&&s[j][k]<=‘Z‘)    s[j][k]+=32;
    if(c[pos]==s[j][k])    return true;
    else return false;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]);
    for(int i=1;i<=m;i++){
        scanf("%s",c);
        for(int j=1;j<=n;j++){
            int len=strlen(s[j]);
            int pos=0;
            for(int k=0;k<len;k++)
                if(judge(pos,j,k))    pos++;
            if(pos==strlen(c))    ans[j]++;
        }
    }
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
}
时间: 2024-08-03 14:38:14

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

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

洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm(恶心的DP)

P2905 [USACO08OPEN]农场危机Crisis on the Farm 1605: [Usaco2008 Open]Crisis on the Farm 牧场危机 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < M < 1000)个高高的草垛. 作为出色的指挥家,约翰可以通过口哨指挥奶牛们移动.他的口哨有四个音,分别能使所有 的牛塔向东南

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

P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < M < 1000)个高高的草垛. 作为出色的指挥家,约翰可以通过口哨指挥奶牛们移动.他的口哨有四个音,分别能使所有 的牛塔向东南西北四个方向移动一格. 每一次,当一个牛塔到达了一个草垛所在的格子,牛塔最上方的奶牛就会跳到

洛谷 P2909 [USACO08OPEN]牛的车Cow Cars

P2909 [USACO08OPEN]牛的车Cow Cars 题目描述 N (1 <= N <= 50,000) cows conveniently numbered 1..N are driving in separate cars along a highway in Cowtopia. Cow i can drive in any of M different high lanes (1 <= M <= N) and can travel at a maximum speed

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

题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < M < 1000)个高高的草垛. 作为出色的指挥家,约翰可以通过口哨指挥奶牛们移动.他的口哨有四个音,分别能使所有 的牛塔向东南西北四个方向移动一格. 每一次,当一个牛塔到达了一个草垛所在的格子,牛塔最上方的奶牛就会跳到草垛上,而且 不再下来,而其他奶牛仍然呈塔状站在草垛所在的格子里.当牛塔只剩一只奶牛

洛谷P2906 [USACO08OPEN]牛的街区Cow Neighborhoods

曼哈顿距离转切比雪夫距离 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define GG int 4 #define For(i, j, k) for(register int i=j; i<=k; i++) 5 #define Dow(i, j, k) for(register int i=j; i>=k; i--) 6 using namespace std; 7 GG read() { 8 GG x = 0, f

洛谷 P3227 BZOJ 3144 [HNOI2013]切糕

题目描述 经过千辛万苦小 A 得到了一块切糕,切糕的形状是长方体,小 A 打算拦腰将切糕切成两半分给小 B.出于美观考虑,小 A 希望切面能尽量光滑且和谐.于是她找到你,希望你能帮她找出最好的切割方案. 出于简便考虑,我们将切糕视作一个长 P.宽 Q.高 R 的长方体点阵.我们将位于第 z层中第 x 行.第 y 列上(1≤x≤P, 1≤y≤Q, 1≤z≤R)的点称为(x,y,z),它有一个非负的不和谐值 v(x,y,z).一个合法的切面满足以下两个条件: 与每个纵轴(一共有 P*Q 个纵轴)有且

洛谷——P1101 单词方阵

https://www.luogu.org/problem/show?pid=1101#sub 题目描述 给一nXn的字母方阵,内可能蕴含多个“yizhong”单词.单词在方阵中是沿着同一方向连续摆放的.摆放可沿着8个方向的任一方向,同一单词摆放时不再改变方向,单词与单词之间[color=red]可以[/color]交叉,因此有可能共用字母.输出时,将不是单词的字母用“*”代替,以突出显示单词.例如: 输入: 8 输出: qyizhong *yizhong gydthkjy gy****** n

斐波那契数列的通项公式x+洛谷P2626x

#include<cstdio> #include<iostream> #include<cmath> using namespace std; int main() { int n; scanf("%d",&n); n--; double q=sqrt(5.0); int ans; ans=((pow((1+q)/2.0,n)/q-(pow((1-q)/2.0,n)/n))); cout<<ans<<endl; re