Skip to main content
  1. Posts/

BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量 (暴力)

·2 mins
Table of Contents
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

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的时限。。。暴力。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年04月04日 星期一 02时10分20秒
 4File Name :code/bzoj/1622.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E3+7;
34string cow[N];
35string eng[105];
36int n,m;
37
38string  aha ( string x)
39{
40    int len = x.length();
41    for ( int i = 0 ; i < len ; i++)
42    {
43	if (x[i]>='A'&&x[i]<='Z') x[i] = char(x[i]+32);
44    }
45    return x;
46}
47
48bool ok (string x,string y)
49{
50  //  cout<<"x:"<<x<<" y:"<<y<<endl;
51    int lx = x.length();
52    int ly = y.length();
53    int j = 0;
54    for ( int i = 0 ; i < lx ; i++)
55    {
56	if (x[i]==y[j]) j++;
57	if (j>=ly) return true;
58    }
59    return false;
60
61}
62int main()
63{
64	#ifndef  ONLINE_JUDGE
65	freopen("code/in.txt","r",stdin);
66  #endif
67
68	ios::sync_with_stdio(false);
69	cin>>n>>m;
70	for ( int i = 1 ; i <= n ; i++) cin>>cow[i],cow[i]=aha(cow[i]);
71	for ( int i = 1 ; i <= m ; i++) cin>>eng[i],eng[i]=aha(eng[i]);
72
73
74	for ( int i = 1 ; i <= n ; i++)
75	{
76
77	    int ans =  0;
78	    for ( int j = 1 ; j <= m ; j++)
79	    {
80		if (ok(cow[i],eng[j])) ans++;
81	    }
82	    cout<<ans<<endl;
83	}
84
85  #ifndef ONLINE_JUDGE
86  fclose(stdin);
87  #endif
88    return 0;
89}

Related

codeforces #346 div 2 C. Tanya and Toys (暴力乱搞)

·2 mins
题目链接 题意:有1E9个礼物,第i个礼物价钱是i,然后现在已经有n个不重复的礼物,a[i],m元钱,想尽可能多得买不同种类的礼物,还能买多少个。 思路:先不考虑已经买的,从1连续买到k,然后考虑子啊这个区间内已经买的,等于实际上没有花钱。 反正就是暴力搞啊搞啊。。我也不知道怎么搞。。 结果最后。。方案数为0的时候。。。最后一个答案我是单独输出的。。忘了判断了。。。所以会输出两个0.宝宝心里苦啊。。。。。。。。

codeforces 334 B. Eight Point Sets (暴力)

·1 min
题目链接 题意:给出8个点,问能否构成一个8元素集合,使得x1/* *********************************************** Author :111qqz Created Time :2016年03月31日 星期四 13时39分27秒 File Name :code/cf/problem/334B.cpp ************************************************ */

codeforces croc2016 A. Amity Assessment (暴力)

·1 min
题目链接 题意:2×2的格子,有三个位置分别放”A“ “B” “C” ,一个位置为空。只有和空位相邻位置上的字母能移动到空位。没有其他移动规则。现在给出两个状态。问能否互相转化。 思路: 貌似可以dfs…?但是一共才2*2,可以直接暴力枚举。 手写一种变换最多能有12种。