URAL-1941 Scary Martian Word 队列维护
来源:互联网 发布:python快速注释快捷键 编辑:程序博客网 时间:2024/04/29 14:15
给出两个字符串A和B,问A的排列在B中出现了多少次。
因为任意排列都符合要求,所以我们只需记录每种数字在子串出现的次数。
先记录出每个值出现了几次,作为需求数。
然后找出B中所有值。
挨个入队,需求值-1,如果一个需求值<0,证明多入队了,从前面开始出队直到需求值为0,如果队内数等于出现次数,ans+1;
//写的很含糊,看代码吧
#include <iostream>#include <cstring>#include <queue>#include <cmath>#include <cstdio>#include <algorithm>#include <map>#define maxn 3000000#define inf 1<<30using namespace std;char s[maxn];char str[maxn];int visit[8000000];//记录每个单词出现了几次 int a[555555];//每个词组的ASC值 int main(){gets(s);gets(str);int len=strlen(s);int cnt=0;memset(visit,0,sizeof(visit));for(int i=0;i<len;i+=4){int t;t=(s[i]-33)*100+(s[i+1]-33)*10+(s[i+2]-33);visit[t]++;cnt++;}len=strlen(str);int n=0;for(int i=0;i<len;i+=4){int t;t=(str[i]-33)*100+(str[i+1]-33)*10+(str[i+2]-33);a[n++]=t;}int p=0;int ans=0;//cout<<cnt<<" "<<n<<endl;if(n<cnt){cout<<"0"<<endl;}else{for(int i=0;i<n;i++)//入队 {visit[a[i]]--;//该值的需求值-1 if(visit[a[i]]<0)//说明这个值多入队了,前面的出队 {while(visit[a[i]]<0)//直到这个值还需求数 为0 {visit[a[p]]++;//出队,需求数+1 p++;//出队的数的个数 }}if(i-p+1==cnt)//i-p+1=队内数,刚好匹配 {ans++;//结果+1 visit[a[p]]++;//出队 p++;//出队个数 }//cout<<p<<endl;}cout<<ans<<endl;}return 0;}
0 0
- URAL-1941 Scary Martian Word 队列维护
- 1941 Scary Martian Word
- 维护队列
- bzoj 2453: 维护队列
- 【bzoj2453】维护队列 分块
- bzoj 2453: 维护队列
- bzoj 2453: 维护队列
- [bzoj2453]维护队列
- 【NOI模拟】维护队列
- bzoj 2453 维护队列
- BZOJ 2453 维护队列
- bzoj2453: 维护队列
- 【bzoj2453】维护队列
- bzoj2453[维护队列]
- 【bzoj2453】 维护队列
- ural 1126【单调队列基础】
- 使用 Word 2013 维护博客
- that was scary
- GoodJob(找工作助手/辅助决策)的帮助
- 关于网页中的meta标签
- 找工作助手GoodJob
- Scala学习之一---基础篇
- Java加密和数字签名编程快速入门
- URAL-1941 Scary Martian Word 队列维护
- android设置全屏
- java中的泛型方法
- learning the shell
- 大数对小数的求余和商
- Spring中使用数据源
- 黑马程序员_C语言之复杂数据类型
- 掌握 Java 泛型类型(一)
- URAL 1942 Attack at the Orbit