AC 暨本人回归王码祭

虚空终端  •  6个月前


也是在洛谷被摁在地上摩擦了一段时间,现在回来切切水题,就从这里记录下我切题的代码吧

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int N=1e5+10;
const int inf=2147483647;

int top=0;
int a[N],s[N];

int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;)
	{
		int minn,t=0;
		if(top==0)
			minn=inf;
		else
			minn=s[top];
		for(int j=i;j-i+top+1<=k&&j<=n;j++)
		{
			if(a[j]<minn)
			{
				minn=a[j];
				t=j-i+1;
//				cout<<t<<' '<<minn<<endl;;
			}
		}
		for(int j=i;j<=i+t-1;j++)
			s[++top]=a[j];
		i+=t;
		if(top!=0)
		{
//			cout<<endl;
//			for(int j=1;j<=top;j++)
//				cout<<s[j]<<' ';
//			cout<<endl;
			cout<<s[top]<<' ';
			top--;
		}
	}
	while(top>0)
	{
		cout<<s[top]<<' ';
		top--;
	}
	return 0;
}

评论:

请先登录,才能进行评论