未按照升序输出依然AC
查看原帖
未按照升序输出依然AC
514850
Acerkaio楼主2022/2/10 16:11

此程序未按照升序输出依然AC:

#include<bits/stdc++.h>
using namespace std;
char s[10101010];
int sum[10101010],q[10101010],ans[10101010];
int n,k;
int main()
{
	cin>>n>>k;
	cin>>s+1;
	int tot=0,num=0;
	for(int i=1;i<=n;i++)
	{
		tot++;
		q[tot]=i;
		if(s[i]=='c')
		{
			sum[tot]=sum[tot-1]+1;
		}
		else
		{
			sum[tot]=sum[tot-1];
		}
		if(sum[tot]-sum[tot-k-1]==1&&tot>=k+1)
		{
			for(int j=tot;j>tot-k-1;j--)
			{
				ans[++num]=q[j];
			}
			tot=tot-k-1;
		}
	}
	int js=0;
	for(int j=num;j>=1;j--)
	{
		++js;
		cout<<ans[j]<<" ";	
		if(js==3)
		{
			cout<<'\n';
			js=0;	
		}
	}
	return 0;
}

样例结果:
10 11 12
1 8 9
2 6 7
3 4 5

而且这个程序也为按升序输出确实30分\kk:

#include<bits/stdc++.h>
using namespace std;
char s[10101010];
int sum[10101010],q[10101010],ans[10101010];
int n,k;
int main()
{
	cin>>n>>k;
	cin>>s+1;
	int tot=0,num=0;
	for(int i=1;i<=n;i++)
	{
		tot++;
		q[tot]=i;
		if(s[i]=='c')
		{
			sum[tot]=sum[tot-1]+1;
		}
		else
		{
			sum[tot]=sum[tot-1];
		}
		if(sum[tot]-sum[tot-k-1]==1&&tot>=k+1)
		{
			for(int j=tot-k;j<=tot;j++)
			{
				ans[++num]=q[j];
			}
			tot=tot-k-1;
		}
	}
	int js=0;
	for(int j=1;j<=num;j++)
	{
		++js;
		cout<<ans[j]<<" ";	
		if(js==3)
		{
			cout<<'\n';
			js=0;	
		}
	}
	return 0;
}
2022/2/10 16:11
加载中...