A - Scary Martian Word

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

There are different superstitions on different planets. Martians laugh at Earthlings suffering Triskaidekaphobia and Hexakosioihexekontahexaphobia. And Earthlings make jokes on the fact that there is a scary word in Martian language. Martians are not only afraid of the word itself, but also of all the words that are obtained by rearrangement of letters in this word.
The Martian alphabet has 729 000 letters. Correspondent Ovchinnikov, who lives on Mars and studies Martian language, represents Martian letters as triplets of symbols with ASCII codes from 33 to 122. He has recently written a book about life and culture on Mars. Before sending the book into press Ovchinnikov wants to count the number of substrings in the text of the book which are frightening for Martians.

Input

The first line contains the scary Martian word, consisting of at most 8 000 Martian letters. The second line contains the text of Ovchinnikov's book, which is at most 500 000 Martian letters long. Both the scary word and the text of the book contain at least one letter. Every Martian letter is represented by the triplet of symbols with ASCII codes from 33 to 122, each letter separated from the next one by a whitespace.

Output

Output the number of substrings in the book by correspondent Ovchinnikov, which are frightening for Martians.

Sample Input

input output
aaa bbb ccc
aaa aaa bbb ccc aaa zzz aaa bbb ccc
3

Notes

Two substrings “aaa bbb ccc” (starting from the second and the seventh positions in the text) and a substring “bbb ccc aaa” are scary for the Martians.
 



#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int cur[maxn*maxn*maxn];
int hash[maxn*maxn*maxn];
char s[];
int change(char *s){
int res=;
for(int i=;i<;i++){
res=maxn*res+s[i];
}
return res;
}
int h[];
int main(){
char c;
int len=;
while(scanf("%s",s)!=EOF){
int temp=change(s);
hash[temp]++;
len++;
c=getchar(); if(c=='\n')
break;
}
int ans=;
int cnt=;
for(int i=;;i++){
scanf("%s",s);
int d=change(s);
h[i]=d;
if(cur[d]<hash[d])
cnt++;
cur[d]++;
if(i>=len){
d=h[i-len];
if(cur[d]<=hash[d])
cnt--;
cur[d]--;
}
if(cnt==len)
ans++;
c=getchar();
if(c=='\n')
break;
}
printf("%d\n",ans);
return ;
}

哈希URAL 1941 - Scary Martian Word的更多相关文章

  1. 1941. Scary Martian Word

    1941. Scary Martian Word 这道题 一个长度为3的字符串视为 一个 火星文 字母(ASCII 33-122) ,给出一个火星人认为恐怖的单词(由火星字母组成) 然后 给你一篇文章 ...

  2. URAL 1941

    比赛的时候三个点没有优化成功.其实也没有想到哈希成数.然后就变成了只要一个长度和scary相等的区间内所有数字个数都是相等的.那么就是符合题意的.于是.为了不TLE我们不能对txt每个位置遍历 的同时 ...

  3. 学习Word2vec

    有感于最近接触到的一些关于深度学习的知识,遂打算找个东西来加深理解.首选的就是以前有过接触,且火爆程度非同一般的word2vec.严格来说,word2vec的三层模型还不能算是完整意义上的深度学习,本 ...

  4. 软工结对项目之词频统计update

    队友 胡展瑞 031602215 作业页面 GitHub 具体分工 111500206 赵畅:负责WordCount的升级,添加新的命令行参数支持(自定义输入输出文件,权重词频统计,词组统计等所有新功 ...

  5. Java对象创建的过程及对象的内存布局与访问定位

    这里以HotSpot为例,且所说的对象指普通的Java对象,不包括数组和Class对象等. 1.对象创建的过程 1.类加载.解析.初始化:虚拟机遇到new时先检查此指令的参数是否能在常量池中找到类的符 ...

  6. UVALive 6320

    .............先让我哭一会....... 因为样例三.... 没敢敲...然后确实是样例错了...然后...上次比赛刚做过的一道类似的题...URAL 1941...大水题啊......悔 ...

  7. synchronized运行原理以及优化

    线程安全问题 线程不安全: 当多线程并发访问临界资源时(可共享的对象),如果破坏原子操作,可能会造成数据不一致. 临界资源:共享资源(同一对象),一次仅允许一个线程使用,才可以保证其正确性. 原子操作 ...

  8. LintCode 550 · Top K Frequent Words II

    题目描述 题目链接 思路 由于要统计每个字符串的次数,以及字典序,所以,我们需要把用户每次add的字符串封装成一个对象,这个对象中包括了这个字符串和这个字符串出现的次数. 假设我们封装的对象如下: p ...

  9. 使用加强堆结构解决topK问题

    作者:Grey 原文地址: 使用加强堆结构解决topK问题 题目描述 LintCode 550 · Top K Frequent Words II 思路 由于要统计每个字符串的次数,以及字典序,所以, ...

随机推荐

  1. javaweb基础(38)_事务

    一.事务的概念 事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功. 例如:A——B转帐,对应于如下两条sql语句  update from account set mone ...

  2. phpmyadmin高级功能尚未完全设置部分功能未激活

    1.登录phpmyadmin,点击导入,选择/var/ww/html/phpmyadmin/examples/create_tables.sql并执行 完成后可以看到多出了一个库phpmyadmin. ...

  3. eclipse 插件relo使用

    1. eclipse插件安装 在线安装地址:http://relo.csail.mit.edu/update 本地配置,文件下载:http://download.csdn.net/download/s ...

  4. 前端JavaScript之DOM节点操作

    1.HTML DOM是啥 Document Object Model:定义了访问和操作HTML文档的标准方法,把HTML文档呈现为带有元素,属性和文本的树状结构 2.解析过程 HTML加载完毕,渲染引 ...

  5. 关于props的注意事项!

    起于昨晚大半夜在群里看到有人问这个问题,在子组件的data属性里重新赋值props属性 this.a = this.propA,不生效! 提示了他如果是异步的话,就要注意watch.决定今日敲个dem ...

  6. 《JSON笔记之三》---postman中传入json串

    1.关于如何使用postman工具,简单的介绍一下, 用户在开发或者调试网络程序或者是网页B/S模式的程序的时候是需要一些方法来跟踪网页请求的,用户可以使用一些网络的监视工具比如著名的Firebug等 ...

  7. IDEA 编辑框光标闪烁

    依次打开如下菜单: File -> Settings -> Editor -> General -> Appearance -> 选中 Caret blinking (m ...

  8. laravel 安装excel扩展

    1,使用Composer安装依赖 在Laravel项目根目录下使用Composer安装依赖: composer require maatwebsite/excel ~2.1 ps:一定要加上~2.1! ...

  9. thinkphp3.2 where 条件查询 复查的查询语句

    复查的查询语句 有的时候,我们希望通过一次的查询就能解决问题,这个时候查询条件往往比较复杂,但是却比多次查询库来的高效. 实在是搞不定的话就直接用$where[‘_string’] = ‘xxxx’, ...

  10. No module named appium

    在脚本中会有:from appium import webdriver 第一次运行时可能会遇到这样的error:No module named appium 之所以会报这样的error是因为没有装cl ...