比赛的时候三个点没有优化成功。其实也没有想到哈希成数。然后就变成了只要一个长度和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. 20145118《Java程序设计》 第9周学习总结

    20145118 <Java程序设计>第9周学习总结 教材学习内容总结 1.SUN公司定义了一套Java操作数据库的规范(接口)来简化数据库操作,称之为JDBC.开发人员只需要学习jdbc ...

  2. C#中基于流的XML文件操作笔记

    System.Xml.XmlReader和System.Xml.XmlWriters是两个抽象类,XmlReader提供了对于XML数据的快速,非缓存,只进模式的读取器,XmlWriter表示一个编写 ...

  3. Python3基础 input 输入浮点数,整数,字符串

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. CodeForces 1105E

    题目链接 std:meet in the middle 首先把所有的点分成两部分,设\(f_i\)为前半部分在点集\(i\)中选出的最大独立集,\(g\)为在后半部分选.这个可以在\(O(2^{m/2 ...

  5. POJ 2152 Fire(树形dp)

    http://poj.org/problem?id=2152 题意: n个节点组成的树,要在树一些点上建立消防站,每个点建站都有个cost[i],每个点如果不在当前的点上建站,也要依赖其他的消防站,并 ...

  6. UVa 12108 特别困的学生

    https://vjudge.net/problem/UVA-12108 题意:给出n个学生的“清醒—睡眠”周期和初始时间点,每个学生在睡眠时需要判断全班睡觉人数是否严格大于清醒人数,否则在坚持一个清 ...

  7. idea oracle反向工程生成实体类

    1. 选择View-Tool Window- Database 2. 配置数据库信息 提示:配置完成后可以通过idea进行sql查询等操作 3.在项目中创建hbernate.cfg.xml文件, 在r ...

  8. python 无序表查找

    def sequential_search(lis, key): for i in range(len(lis)): if(lis[i] == key): return i else: return ...

  9. 【Robot Framework 项目实战 02】SeleniumLibrary Web UI 自动化

    前言 SeleniumLibrary 是针对 Robot Framework 开发的 Selenium 库.它也 Robot Framework 下面最流程的库之一.主要用于编写 Web UI 自动化 ...

  10. Python 爬虫-Scrapy爬虫框架

    2017-07-29 17:50:29 Scrapy是一个快速功能强大的网络爬虫框架. Scrapy不是一个函数功能库,而是一个爬虫框架.爬虫框架是实现爬虫功能的一个软件结构和功能组件集合.爬虫框架是 ...