1114 - Easily Readable
| Time Limit: 2 second(s) | Memory Limit: 32 MB |
As you probably know, the human information processor is a wonderful text recognizer that can handle even sentences that are garbled like the following:
The ACM Itrenntaoial Clloegaite Porgarmmnig Cnotset (IPCC) porvdies clolgee stuetnds wtih ooppriuntetiis to itnrecat wtih sutednts form ohetr uinevsrtieis.
People have claimed that understanding these sentences works in general when using the following rule: The first and last letters of each word remain unmodified and all the characters in the middle can be reordered freely. Since you are an ACM programmer, you immediately set on to write the following program: Given a sentence and a dictionary of words, how many different sentences can you find that could potentially be mapped to the same encoding?
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with a line containing the number n (0 ≤ n ≤ 10000) of words in the dictionary, which are printed on the following n lines. After this, there is a line containing the number m (0 ≤ m ≤ 10000)of sentences that should be tested with the preceding dictionary and then m lines containing those sentences. The sentences consist of letters from a to z, A to Z and spaces only and have a maximal length of10000 characters. For each word in the dictionary a limitation of 100 characters can be assumed. The words are case sensitive. In any case, total number of characters in the sentences will be at most 105. And total characters in the dictionary will be at most 105.
Output
For each case, print the case number first. Then for each sentence, output the number of sentences that can be formed on an individual line. Result fits into 32 bit signed integer.
Sample Input |
Output for Sample Input |
|
1 8 baggers beggars in the blowed bowled barn bran 1 beggars bowled in the barn |
Case 1: 8 |
Note
Dataset is huge, use faster I/O methods.
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<stack>
7 #include<map>
8 #include<math.h>
9 #include<stack>
10 using namespace std;
11 typedef long long LL;
12 char str[105];
13 char bb[100006];
14 char ak[105];
15 void in(char *v);
16 int ask(char *vv);
17 int tree[100006][52];
18 int val[100006];
19 int nn=0;
20 int sk=1;
21 int main(void)
22 {
23 int i,j,k;
24 scanf("%d",&k);
25 int s;
26 for(s=1; s<=k; s++)
27 {
28 int n,m;sk=1;
29 memset(tree,-1,sizeof(tree));
30 memset(val,0,sizeof(val));
31 scanf("%d ",&n);
32 for(i=0; i<n; i++)
33 {
34 scanf("%s",str);
35 int l=strlen(str);
36 if(l>=3)
37 sort(str+1,str+l-1);
38 str[l]='\0';
39 in(str);
40 }
41 scanf("%d",&m);
42 printf("Case %d:\n",s);
43 getchar();
44 while(m--)
45 {
46 gets(bb);
47 if(bb[0]=='\0')printf("1\n");
48 else
49 {
50 int l=strlen(bb);
51 int uu=0;
52 int flag=0;
53 LL sum=1;
54 bb[l]=' ';
55 for(i=0; i<=l; i++)
56 {
57 if(bb[i]!=' ')
58 {
59 flag=1;
60 ak[uu++]=bb[i];
61 }
62 else if(flag==1&&bb[i]==' ')
63 {
64 flag=0;
65 ak[uu]='\0';
66 if(uu>=3)
67 sort(ak+1,ak+uu-1);
68 sum*=(LL)ask(ak);
69 uu=0;
70 }
71 }
72 printf("%lld\n",sum);
73 }
74 }
75 }
76 return 0;
77 }
78 void in(char *v)
79 {
80 int l=strlen(v);
81 int i,j;
82 int cc;
83 int k=0;
84 for(i=0; i<l; i++)
85 {
86 if(v[i]>='A'&&v[i]<='Z')
87 {
88 cc=v[i]-'A'+26;
89 }
90 else
91 cc=v[i]-'a';
92 if(tree[k][cc]==-1)
93 {
94 tree[k][cc]=sk;
95 k=sk;
96 sk++;
97 nn++;
98 }
99 else k=tree[k][cc];
100 }
101 val[k]++;
102 }
103 int ask(char *vv)
104 {
105 int l=strlen(vv);
106 int i,j;
107 int cc;
108 int ak=0;
109 for(i=0; i<l; i++)
110 {
111 if(vv[i]>='A'&&vv[i]<='Z')
112 {
113 cc=vv[i]-'A'+26;
114 }
115 else
116 cc=vv[i]-'a';
117 if(tree[ak][cc]==-1)
118 return 0;
119 ak=tree[ak][cc];
120 }
121 return val[ak];
122 }
1114 - Easily Readable的更多相关文章
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- iOS编码规范
The official raywenderlich.com Objective-C style guide. This style guide outlines the coding con ...
- 使用神经网络来识别手写数字【译】(三)- 用Python代码实现
实现我们分类数字的网络 好,让我们使用随机梯度下降和 MNIST训练数据来写一个程序来学习怎样识别手写数字. 我们用Python (2.7) 来实现.只有 74 行代码!我们需要的第一个东西是 MNI ...
- About SQLite
About SQLite See Also... Features When to use SQLite Frequently Asked Questions Well-known Users Boo ...
- js高级应用
特别板块:js跨域请求Tomcat6.tomcat7 跨域设置(包含html5 的CORS) 需要下载两个jar文件,cors-filter-1.7.jar,Java-property-utils-1 ...
- MySQL入门手册
本文内容摘自MySQL5.6官方文档,主要选取了在实践过程中所用到的部分文字解释,力求只摘录重点,快速学会使用MySQL,本文所贴代码地方就是我亲自练习过的代码,凡本文没有练习过的代码都没有贴在此处, ...
- javascript对json对象的序列化与反序列化
首先引入一个json2.js.官方的地址为:https://github.com/douglascrockford/JSON-js 这里为了方便我直接贴上源代码 /* json2.js 2013-05 ...
- iOS 注释的5要3不要和编码规范的26个方面
注释 代码注释,可以说是比代码本身更重要.这里有一些方法可以确保你写在代码中的注释是友好的: 不要重复阅读者已经知道的内容 能明确说明代码是做什么的注释对我们是没有帮助的. // If the col ...
- Effective Java 47 Know and use the libraries
Advantages of use the libraries By using a standard library, you take advantage of the knowledge of ...
随机推荐
- 扩展kmp 学习笔记
学习了一下这个较为冷门的知识,由于从日报开始看起,还是比较绕的-- 首先定义 \(Z\) 函数表示后缀 \(i\) 与整个串的 \(lcp\) 长度 一个比较好的理解于实现方式是类似于 \(manac ...
- Maven打包及场景
场景一 对当前项目打包并指定主类. <build> <plugins> <plugin> <artifactId>maven-compiler-plug ...
- 大数据学习day15----第三阶段----scala03--------1.函数(“_”的使用, 函数和方法的区别)2. 数组和集合常用的方法(迭代器,并行集合) 3. 深度理解函数 4 练习(用java实现类似Scala函数式编程的功能(不能使用Lambda表达式))
1. 函数 函数就是一个非常灵活的运算逻辑,可以灵活的将函数传入方法中,前提是方法中接收的是类型一致的函数类型 函数式编程的好处:想要做什么就调用相应的方法(fliter.map.groupBy.so ...
- css系列,选择器权重计算方式
CSS选择器分基本选择器(元素选择器,类选择器,通配符选择器,ID选择器,关系选择器), 属性选择器,伪类选择器,伪元素选择器,以及一些特殊选择器,如has,not等. 在CSS中,权重决定了哪些CS ...
- 【leetcode】153. Find Minimum in Rotated Sorted Array
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example ...
- 容器的分类与各种测试(二)——vector部分用法
向量 vector 是一种对象实体, 能够容纳许多其他类型相同的元素, 因此又被称为容器. 与string相同, vector 同属于STL(Standard Template Library, 标准 ...
- 访问网页全过程,用wireshark抓包分析
用wireshark抓包查看访问网站过程 打开wireshark,打开一个无痕浏览器,输入网址,到网页呈现这一过程,网络数据包传递的消息都会被放在wireshark里.针对这些包,我们可以逐一分析,摸 ...
- EFK的安装和收集docker容器日志展示
在用户根目录创建个filebeat.docker.yml文件,文件内容如下 filebeat.config: modules: path: ${path.config}/modules.d/*.yml ...
- 修复Apache Log4j任意代码执行漏洞安全风险通告
2021年12月10日 0x01漏洞背景 Apache Log4j 是 Apache 的一个开源项目,Apache Log4j2是一个基于Java的日志记录工具.该工具重写了Log4j框架,并且引入了 ...
- DevOps到底是什么意思?
目录 一.方法论 二.DevOps的起源 三.DevOps到底是什么 四.DevOps的发展现状 五.DevOps与虚拟化.容器.微服务 一.方法论 提到DevOps这个词,我相信很多人一定不会陌生. ...