首页 > ACM题库 > HDU-杭电 > HDU 2946-Letter Cookies[解题报告]HOJ
2014
02-24

HDU 2946-Letter Cookies[解题报告]HOJ

Letter Cookies

问题描述 :

Satre has finally decided to put their famous Letter Cookies back on market again. Of course they are just as interesting to play with as to eat. Your little sister is trying to make words out of the letters she found in the box, but you want to be faster than her to decide whether it is possible to make the word or not.


Given the letters in the cookie box, is it possible to spell out the words your little sister knows how to spell? (After creating a word, she scrambles the cookies again and can reuse the letters for later words.)

输入:

The first line of the input consists of a single number T, the number of letter cookie boxes your sister has. Each test case starts with a line describing all the letters in this box, in no particular order. Then follows a line with W, the number of words she would like to spell, and then follow the W words to write on a single line each.

输出:

The first line of the input consists of a single number T, the number of letter cookie boxes your sister has. Each test case starts with a line describing all the letters in this box, in no particular order. Then follows a line with W, the number of words she would like to spell, and then follow the W words to write on a single line each.

样例输入:

1
ABANANACOOKIE
4
BANANA
LETTER
COOKIES
CAN

样例输出:

YES
NO
NO
YES

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#define PB push_back
#define MP make_pair
#define clr(a,b) (memset(a,b,sizeof(a)))
#define rep(i,a) for(int i=0; i<(int)a.size(); i++)

const int INF = 0x3f3f3f3f;
const double eps = 1E-8;

int a[30],b[30];
char s[2000],ss[2000];
int T,n;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",s);
		int len = strlen(s);
		clr(a,0);
		for(int i=0; i<len ; i++)	a[s[i]- 'A' ]++;

		scanf("%d",&n);
		while(n--)
		{
			clr(b,0);
			scanf("%s",ss);
			int l = strlen(ss);
			for(int i=0; i<l; i++)	b[ss[i] - 'A']++;

			bool ok = true;
			for(int i=0; i<26; i++)
				if(b[i] > a[i])
					ok = false;

			if(ok)	puts("YES");
			else	puts("NO");
		}


	}

	return 0;
}

  1. simple, however efficient. A lot of instances it is difficult to get that a??perfect balancea?? among usability and appearance. I must say that youa??ve done a exceptional task with this. Also, the blog masses quite fast for me on Web explore.

  2. 算法是程序的灵魂,算法分简单和复杂,如果不搞大数据类,程序员了解一下简单点的算法也是可以的,但是会算法的一定要会编程才行,程序员不一定要会算法,利于自己项目需要的可以简单了解。