POJ 1754 Buffer Manager G++
程序员文章站
2022-07-15 11:07:50
...
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
//英语 看博友分析 抄博友程序 模拟
char s[100010];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int js=0;
int he=0;
int jg=0x7fffffff;
int pos;
//string s="*2165745216091853477755800393859785807207523169954341**7363*9*94664808*477771708909825185827659480548";
for(int i=1;i<=n;i++)
{
char ch;
scanf("%c",&ch);
s[i]=ch;
if(s[i]=='\n')
{
i--;
}else if(s[i]=='*')
{
js=0;
he=0;
}else
{
js++;
if(js>m)
{
he=he+s[i]-'0'-(s[i-m]-'0');
if(jg>he)
{
jg=he;
pos=i-m+1;
//cout<<jg<<" "<<pos<<endl;
}
}else if(js<m)
{
he=he+s[i]-'0';
}else if(js==m)
{
he=he+s[i]-'0';
if(jg>he)
{
jg=he;
pos=i-m+1;
//cout<<jg<<" "<<pos<<endl;
}
}
//cout<<i<<" "<<he<<endl;
}
}
if(jg==0x7fffffff)
{
cout<<0<<endl;
}else
{
cout<<pos<<endl;
}
return 0;
}