比赛的时候三个点没有优化成功。其实也没有想到哈希成数。然后就变成了只要一个长度和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. BZOJ 1063 道路设计(树形DP)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1063 题意:给出一个无环图( 也就是树,但是也有可能是森林),代表一个国家的城市.1是首 ...

  2. 启动jenkins服务错误

    背景 重新安装了jenkins,需要启动,使用的yum install安装的,启动jenkins的话只需要执行service jenkins start,但出了两个问题 1. 是提示找不到java 2 ...

  3. mysql 通过binlog 查看执行日志

    环境:linux deepin15.7   mysql 5.7 1.开启binlog vim /etc/mysql/mysql.conf.d/mysqld.cnf 添加 log_bin = /var/ ...

  4. kafka删除一个topic

    前言 当我们在shell中执行topic删除命令的时候` kafka-topics --delete --topic xxxx --zookeeper xxx`,会显示,xxxx已经被标记为删除.然后 ...

  5. Ubuntu 下 su:authentication failure的解决办法

    Ubuntu下使用 su 切换到超级用户时候遇到下面的问题 su: Authentication failure 解决办法: $ sudo passwd root Enter new UNIX pas ...

  6. HDU 4587 TWO NODES(割两个点的最大连通分支数)

    http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 给一图,求割去两个点后所能形成的最大连通分支数. 思路: 对于这种情况,第一个只能枚举,然后在删除 ...

  7. UVa 10285 最长的滑雪路径(DAG上的最长路)

    https://vjudge.net/problem/UVA-10285 题意: 在一个R*C的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩 ...

  8. hdu 5671 Matrix 标记。。。有点晕

    Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem ...

  9. Kali Linux下常用软件安装及配置

    0x00 Synaptic Synaptic(新立得)是一个高级软件包管理器,它可以管理系统内安装的每个软件及包组件,在图形界面内完成LINUX系统软件的搜寻.安装和删除. Synaptic安装简单, ...

  10. android开发:Android 中自定义属性(attr.xml,TypedArray)的使用

    今天我们的教程是根据前面一节扩展进行的,如果你没有看,请点击 Android高手进阶教程(三)查看第三课,这样跟容易方便你的理解! 在xml 文件里定义控件的属性,我们已经习惯了android:att ...