「BZOJ1622」[Usaco2008 Open] Word Power 名字的能量
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”.
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”.
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”.
题解
直接模拟T T
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define ll long long #define inf 1000000000 using namespace std; inline ll read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,ans[1005]; char a[1005][1005],b[105][35]; inline bool equ(char a,char b) { if(a<'a'||a>'z')a=a-'A'+'a'; if(b<'a'||b>'z')b=b-'A'+'a'; return a==b; } inline bool jud(int x,int y) { int l1=strlen(b[x]+1),l2=strlen(a[y]+1); int now=1; for(int i=1;i<=l2;i++) if(equ(b[x][now],a[y][i]))now++; if(now==l1+1)return 1; return 0; } void solve(int x) { for(int i=1;i<=n;i++) if(jud(x,i))ans[i]++; } int main() { n=read();m=read(); for(int i=1;i<=n;i++) scanf("%s",a[i]+1); for(int i=1;i<=m;i++) scanf("%s",b[i]+1); for(int i=1;i<=m;i++) solve(i); for(int i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; } |
Subscribe