Google Code Jam 2009 Qualification Round Problem A. Alien Language
https://code.google.com/codejam/contest/90101/dashboard#s=p0
Problem
After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase letters. Also, there are exactly D words in this language.
Once the dictionary of all the words in the alien language was built, the next breakthrough was to discover that the aliens have been transmitting messages to Earth for the past decade. Unfortunately, these signals are weakened due to the distance between our two planets and some of the words may be misinterpreted. In order to help them decipher these messages, the scientists have asked you to devise an algorithm that will determine the number of possible interpretations for a given pattern.
A pattern consists of exactly L tokens. Each token is either a single lowercase letter (the scientists are very sure that this is the letter) or a group of unique lowercase letters surrounded by parenthesis ( and ). For example: (ab)d(dc) means the first letter is either a or b, the second letter is definitely d and the last letter is either d or c. Therefore, the pattern (ab)d(dc) can stand for either one of these 4 possibilities: add, adc, bdd, bdc.
Input
The first line of input contains 3 integers, L, D and N separated by a space. D lines follow, each containing one word of length L. These are the words that are known to exist in the alien language. N test cases then follow, each on its own line and each consisting of a pattern as described above. You may assume that all known words provided are unique.
Output
For each test case, output
Case #X: K
where X is the test case number, starting from 1, and K indicates how many words in the alien language match the pattern.
Limits
Small dataset
1 ≤ L ≤ 10
1 ≤ D ≤ 25
1 ≤ N ≤ 10
Large dataset
1 ≤ L ≤ 15
1 ≤ D ≤ 5000
1 ≤ N ≤ 500
Sample
| Input |
Output |
3 5 4 |
Case #1: 2 |
Solution:
int solve(int L, int D, vector<string>dictionary, string pattern)
{ int matches = ; for (int di = ; di < dictionary.size(); di++) {
string dw = dictionary.at(di); bool bracket = false;
bool inbracket_match = false;
bool word_match = true;
int cci = ;
for (int i = ; i < pattern.length(); i++) {
char chr = pattern[i];
if (chr == '(') {
bracket = true;
} else if (chr == ')') {
bracket = false;
if (!inbracket_match) {
word_match = false;
break;
}
inbracket_match = false;
cci++;
} else {
if (bracket) {
if (dw[cci] == chr) {
inbracket_match = true;
}
} else {
if (dw[cci] != chr) {
word_match = false;
break;
}
cci++;
}
}
} if (word_match) {
matches++;
} } return matches; } int main() {
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout); int L, D;
scanf("%d\n", &L);
scanf("%d\n", &D); int CN;
scanf("%d\n", &CN);
if (!CN) {
cerr << "Check input!" << endl;
exit();
} vector<string> dict;
for (int di = ; di < D; di++) {
char *word = new char[L];
scanf("%s\n", word);
string strword = string(word, L);
dict.push_back(strword);
} for (int case_i = ; case_i <= CN; case_i++) {
string pattern;
cin >> pattern; auto result = solve(L, D, dict, pattern);
printf("Case #%d: %d\n", case_i, result);
} fclose(stdin);
fclose(stdout);
return ;
}
Google Code Jam 2009 Qualification Round Problem A. Alien Language的更多相关文章
- Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam
本题的 Large dataset 本人尚未解决. https://code.google.com/codejam/contest/90101/dashboard#s=p2 Problem So yo ...
- Google Code Jam 2009 Qualification Round Problem B. Watersheds
https://code.google.com/codejam/contest/90101/dashboard#s=p1 Problem Geologists sometimes divide an ...
- [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
- [C++]Standing Ovation——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
- Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha
Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...
- Google Code Jam 2014 资格赛:Problem D. Deceitful War
This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...
- [刷题]Google Code Jam 2017 - Round1 C Problem A. Ample Syrup
https://code.google.com/codejam/contest/3274486/dashboard Problem The kitchen at the Infinite House ...
- Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)
Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...
- Google Code Jam 2014 资格赛:Problem C. Minesweeper Master
Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...
随机推荐
- React 16 源码瞎几把解读 【三 点 一】 把react组件对象弄到dom中去(矛头指向fiber,fiber不解读这个过程也不知道)
一.ReactDOM.render 都干啥了 我们在写react的时候,最后一步肯定是 ReactDOM.render( <div> <Home name="home&qu ...
- curl: (6) Couldn’t resolve host ‘www.ttlsa.com’【转】
上周, 部分站点出现Couldn't resolve host.....问题, 导致公司所有走api的程序都无法正常使用(系统redhat 6.3的都出现问题, redhat 5一切OK). 最后解 ...
- [转载]Selenium実行中にJavaScriptのコードを実行する
Selenium実行中にJavaScriptのコードを実行する JavaScriptで画面の値を取得/設定するコードをメモ. WebDriverEx.cs // JavaScriptを実行(戻り値なし ...
- 2017 ACM ICPC Asia Regional - Daejeon
2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...
- 「caffe编译bug」python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
在Makefile.config找到PYTHON_INCLUDE,发现有点不同: PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib ...
- php琐碎
1.类中的常量,可以用类来引用: class MyClass() { const SUCCESS ="success"; const FAIL ="fail"; ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- 线性SVM的推导
线性SVM算法的一般过程 线性SVM的推导 超平面方程 SVM是用来分类的.给定一系列输入数据(n维向量),需要找到一个切分界线(n-1维的超平面),这里假定数据是线性可分的.比如,二维数据的超平面是 ...
- Hive2.x 版本的安装及配置 以及要注意的事项
博主学习Hadoop学习到Hive,一开始跟着资料去安装Hive 1.x一点问题也没有,方便快捷啊,但是看了一下官方文档,上面好像说Hive 2.0修复了很多bug,那么我想,我还是用Hive2.0好 ...
- python开发学习-day08(socket高级、socketserver、进程、线程)
s12-20160305-day08 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...