50分,tle了后五个点
查看原帖
50分,tle了后五个点
124143
Countjoyyauldly楼主2020/6/22 09:46

帮忙康康?(弱(。・・)ノ

#include<bits/stdc++.h>
using namespace std;
int n,k,b;
queue<char>ser;
int br[100005];
char sd[100005];
int sum;
int ans;
int minn=21473648;
int main()
{
    cin>>n>>k>>b;
    for(int i=1; i<=b; i++)
        cin>>br[i];
    sort(br+1,br+b+1);
    memset(sd,' ',sizeof(sd));
    for(int i=1; i<=b; i++)
        sd[br[i]]='*';
    for(int i=1;i<=k;i++)
        ser.push(sd[i]);
    sum=ser.size();
    while(sum<n)
    {
        for(int i=1;i<=k;i++)
        {
            if(ser.front()=='*')
                ans++;
            ser.pop();
        }
        sum++;
        for(int i=sum-k+1;i<=sum+1;i++)
        ser.push(sd[i]);
        //cout<<"ans:"<<ans<<" ";
        minn=min(ans,minn);
        ans=0;
    }
    cout<<minn;
    return 0;
}

2020/6/22 09:46
加载中...