水题,数学题,在长度为L的数列中求长度为K的和最小的连续子数列。
CO
/*
PROGRAM: $PROGRAM
AUTHOR: Su Jiao
DATE: 2010-3-30
DESCRIPTION:
$DESCRIPTION
*/
#include <iostream>
using std::cin;
using std::cout;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <sstream>
using std::stringstream;
using std::endl;
#include <vector>
using std::vector;
#include <string>
using std::string;
#include <stack>
using std::stack;
#include <queue>
using std::queue;
#include <set>
using std::set;
#include <map>
using std::map;
using std::pair;
using std::make_pair;
#include <algorithm>
using std::sort;
#include <cassert>
//using std::assert;
class Application
{
static const long long int oo=1000000000;
int N,K,L;
vector<long long int> da
vector<long long int> sum;
public:
Application()
{
cin>>N>>K;
da
for (int i=0;i<N;i++)
{
char c;
cin>>c;
if (c==’*’) da
else da
}
}
int run()
{
sum.resize(N+1);
sum[0]=0;
for (int i=0;i<N;i++)
sum[i+1]=sum[i]+da
long long int min=oo;
L=0;
for (int i=0;i<=N-K;i++)
if (sum[i+K]-sum[i]<min)
{
L=i+1;
min=sum[i+K]-sum[i];
}
cout<<L<<endl;
return 0;
}
};
int main()
{
Application app;
return app.run();
}