记录编号 |
2003 |
评测结果 |
AAAAAAAAAAAAAAAA |
题目名称 |
翻译玛雅著作 |
最终得分 |
100 |
用户昵称 |
zqzas |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.705 s |
提交时间 |
2008-09-10 20:50:12 |
内存使用 |
0.00 MiB |
显示代码纯文本
#include <stdio.h>
#define maxn 3010
#define maxlong 3000010
int ans,len1,len2,goal,hash[10000];
char data[maxn],s[maxlong];
FILE *f1,*f2;
void run(void)
{
int i,j,c=0,now[maxn]={0};
for (i=0;i<len1;i++)
{
now[s[i]]++;
if (hash[s[i]]==0)
continue;
if (now[s[i]]==hash[s[i]])
c++;
if (now[s[i]]-1==hash[s[i]])
c--;
}
for (i=0;i<=len2-len1-1;i++)
{
j=i+len1;
if (c==goal)
ans++;
now[s[i]]--;
now[s[j]]++;
if (s[i]==s[j])
continue;
if (hash[s[i]]!=0 && now[s[i]]==hash[s[i]])
c++;
if (hash[s[j]]!=0 && now[s[j]]==hash[s[j]])
c++;
if (hash[s[i]]!=0 && now[s[i]]+1==hash[s[i]])
c--;
if (hash[s[j]]!=0 && now[s[j]]-1==hash[s[j]])
c--;
}
if (c==goal)
ans++;
}
void ini(void)
{
int i;
fscanf(f1,"%d%d",&len1,&len2);
fscanf(f1,"%s%s",&data,&s);
for (i=0;i<len1;i++)
{
if (hash[data[i]]==0)
goal++;
hash[data[i]]++;
}
}
int main(void)
{
f1=fopen("writing.in","r");
f2=fopen("writing.out","w");
ini();
run();
fprintf(f2,"%d",ans);
return 0;
}