BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量 (暴力)
1622: [Usaco2008 Open]Word Power 名字的能量
Time Limit: 5 Sec Memory Limit: 64 MB Submit: 462 Solved: 228 [Submit][Status][Discuss]
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".
思路:复杂度1E8..5S的时限。。。暴力。。
/* ***********************************************
Author :111qqz
Created Time :2016年04月04日 星期一 02时10分20秒
File Name :code/bzoj/1622.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=1E3+7;
7string cow[N];
8string eng[105];
9int n,m;
1string aha ( string x)
2{
3 int len = x.length();
4 for ( int i = 0 ; i < len ; i++)
5 {
6 if (x[i]>='A'&&x[i]<='Z') x[i] = char(x[i]+32);
7 }
8 return x;
9}
1bool ok (string x,string y)
2{
3 // cout<<"x:"<<x<<" y:"<<y<<endl;
4 int lx = x.length();
5 int ly = y.length();
6 int j = 0;
7 for ( int i = 0 ; i < lx ; i++)
8 {
9 if (x[i]==y[j]) j++;
10 if (j>=ly) return true;
11 }
12 return false;
1}
2int main()
3{
4 #ifndef ONLINE_JUDGE
5 freopen("code/in.txt","r",stdin);
6 #endif
1 ios::sync_with_stdio(false);
2 cin>>n>>m;
3 for ( int i = 1 ; i <= n ; i++) cin>>cow[i],cow[i]=aha(cow[i]);
4 for ( int i = 1 ; i <= m ; i++) cin>>eng[i],eng[i]=aha(eng[i]);
for ( int i = 1 ; i <= n ; i++)
{
1 int ans = 0;
2 for ( int j = 1 ; j <= m ; j++)
3 {
4 if (ok(cow[i],eng[j])) ans++;
5 }
6 cout<<ans<<endl;
7 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}