$全 部 爆 零$
  • 板块P1323 删数问题
  • 楼主mot1ve
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/9/2 16:00
  • 上次更新2023/11/5 13:49:27
查看原帖
$全 部 爆 零$
250699
mot1ve楼主2020/9/2 16:00

样例可过

#include<bits/stdc++.h>
using namespace std;
int k,m,d,p1,p2;
int a[10000010],ans[10000010],cut[10000010];//ans存每一位,和一个字符串没区别 
priority_queue<int,vector<int>,greater<int> > q;//小根堆放集合元素 
int main()
{
	cin>>k>>m;
	q.push(1);
	while(1)
	{
		int x=q.top();
		d=0;
		q.pop();
		q.push(2*x+1);
		q.push(4*x+5);
		a[++p1]=x;//确保a数组单调递增 
		while(x)
		{
			d=d*10+x%10;
			x/=10;
		}//倒置
		while(d)
		{
			ans[++p2]=d%10;//按位存,%10是取出个位 
			d/=10;
		}
		if(p1>=k)
		break;
	}
	for(int i=1;i<=p1;i++)
	{
		printf("%d",a[i]);
	}
	printf("\n");
	int cnt=0;
	while(1)
	{
		for(int i=1;i<=p2;i++)
	    {
		   if(ans[i]<ans[i+1]&&!cut[i])
		   {
			   cut[i]=1;//被删去了,一会不输出就行
			   cnt++;
			   if(cnt>=m)
			   {
			   	    for(int j=1;j<=p2;j++)
	                {
		                if(!cut[j])
		                printf("%d",ans[j]);
	                }
	                return 0;
			   }	
		   }
    	}
	}
	return 0;
}
2020/9/2 16:00
加载中...