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

这个代码好有智慧。数据不极端的情况下是不会超时的。

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std; #define maxn 2000010
#define maxm 32010 char txt[maxn], sc[maxm]; // 输入的字符串
int th[], sh[]; // th[]存txt中每个字符的值是多少.sh[]数组存scary字符串中每个字符对应值有多少个。 int main()
{
while(gets(sc))
{
int cnt1 = , cnt2 = ;
memset(sh, , sizeof(sh));
memset(th, , sizeof(th)); int len = strlen(sc);
for (int i=; i<len; i+=)
{
int temp = sc[i] - ;
sh[temp]++;
cnt1++;
} gets(txt);
len = strlen(txt);
for (int i=; i<len; i+=)
{
int temp = txt[i] - ;
th[cnt2] = temp;
cnt2++;
} int st = ; // 从第一个点依次遍历从每个点开始到此后cnt1区间是不是对应值个数相等。
int ans = ;
for (int i=; i<cnt2; ++i)
{
sh[th[i]]--;
while (sh[th[i]]<) //比较过程中遇见一个个数不足 或者 scary里没出现的字符起点就要从这里开始
{
sh[th[st]]++; //同时起点前面那些都回溯没有访问过
st++;
}
if (i-st+ == cnt1) //如果此时长度和scary相同。一定就是个数相同.ans++;
{
ans++;
sh[th[st]]++;
st++;
}
}
printf("%d\n", ans);
}
return ;
}

L哦哦K

URAL 1941的更多相关文章

  1. 哈希URAL 1941 - Scary Martian Word

    A - Scary Martian Word Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  2. UVALive 6320

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

  3. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  4. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  5. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  6. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  7. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  8. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  9. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

随机推荐

  1. UVa 10891 Game of Sum - 动态规划

    因为数的总和一定,所以用一个人得分越高,那么另一个人的得分越低. 用$dp[i][j]$表示从$[i, j]$开始游戏,先手能够取得的最高分. 转移通过枚举取的数的个数$k$来转移.因为你希望先手得分 ...

  2. 关于ActiveMQ、RocketMQ、RabbitMQ、Kafka一些总结和区别

    这是一篇分享文 转自:http://www.cnblogs.com/williamjie/p/9481780.html  尊重原作,谢谢 消息队列 为什么写这篇文章? 博主有两位朋友分别是小A和小B: ...

  3. window 环境下jdbc访问启用kerberos的impala

    最近,公司生产集群添加kerberos安全认证后,访问集群的任何组件都需要进行认证,这样问题来了,对于impala,未配置kerberos安全认证之前通过impala的jdbc驱动(impala-jd ...

  4. Change the Forwarding: RMT Architecture

    Change the Forwarding: RMT Architecture Note on "Forwarding Metamorphosis: Fast Programmable Ma ...

  5. Ubuntu 14.04 下 OF-Config安装

    参考: Github of-config configure.ac - configure file issue OF-Config安装 1.安装OvS v2.3.1: Releases $ tar ...

  6. 推荐一个SAM文件中flag含义解释工具--转载

    SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这样的文件.samtools网站上有专门的文档介绍SAM文件.具体地址:http://samtools. ...

  7. Java入门:零碎的知识点

    实例变量经常被称为属性 成员变量和局部变量:前者在类中定义,后者在类的方法中定义且系统不会自动赋初始值 我们创建一个对象的时候实际上执行的是无参的构造方法 静态变量 static String arr ...

  8. 《剑指offer》第三十二题(分行从上到下打印二叉树)

    // 面试题32(二):分行从上到下打印二叉树 // 题目:从上到下按层打印二叉树,同一层的结点按从左到右的顺序打印,每一层 // 打印到一行. #include <cstdio> #in ...

  9. 《剑指offer》第十二题(矩阵中的路径)

    // 面试题:矩阵中的路径 // 题目:请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有 // 字符的路径.路径可以从矩阵中任意一格开始,每一步可以在矩阵中向左.右. // 上.下移动 ...

  10. Unity如何判断一个对象是不是一件衣服

    判断该对象及其子对象上是否有SkinnedMeshRenderer组价即可 public static bool IsCloth(Transform obj) { bool isCloth = fal ...