记录编号 259459 评测结果 AAAAAAAAAA
题目名称 958.Number 最终得分 100
用户昵称 哒哒哒哒哒! 是否通过 通过
代码语言 C++ 运行时间 0.113 s
提交时间 2016-05-09 16:59:29 内存使用 0.28 MiB
显示代码纯文本
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<queue> 
using namespace std;
int K,M;
int cnt,len;
queue<int>a,b;
string s;
void get(int x){
	char ch[12];
	sprintf(ch,"%d",x);
	for(int i=0;ch[i]!='\0';i++) s+=ch[i];
}
void dp(int l,int n){
	if(n==0) return;
	int pos=l;
	for(int i=l;i<len-n+1;i++){
		if(s[pos]<s[i]) pos=i;
		if(s[pos]=='9') break;
	}
	putchar(s[pos]);
	dp(pos+1,n-1);
}
int main()
{
	freopen("numbera.in","r",stdin);freopen("numbera.out","w",stdout);
	scanf("%d%d",&K,&M);
	a.push(1);b.push(1);
	while(cnt<K){
		int x=a.front();
		int y=b.front();
		int xx=0;
		if(x==y){xx=x;a.pop();b.pop();}
		else if(x>y){xx=y;b.pop();}
		else{xx=x;a.pop();}
		a.push(xx*2+1);
		b.push(xx*4+5);
		get(xx);
		cnt++;
	}
	cout<<s<<endl;
	len=s.length();
	int n=len-M;
	dp(0,n);
	//fclose(stdin);fclose(stdout);
	return 0;
}