Pku2856 我的第一百道题!

一百道题目了,整个集训的末尾,我也达到了这个三位数,虽然不是很厉害,对我来说是另外的一个起点。开始向更低的AC率的题目挑战。100道题目,做出来我也觉得不容易! 

我的第一百道题是最近的一次Pku比赛题目,当时没有做出来,今天完成了,觉得我的想法都是正确的,但是编出来后改了好久才AC!

截个图留念:

 

我的程序代码:

Repeatless Numbers
Time Limit:1000MS  Memory Limit:65536K
Total Submit:400 Accepted:196

Description

 

Input

 

Output

 

Sample Input

 

Sample Output

 

Source
Stanford Local 2004

#include "iostream"

using namespace std;

int main()
{
	int N,i,j,j1,data[11],k,d;
	int flag[11],r,t;
	while(cin>>N&&N)
	{
		memset(flag,0,sizeof(flag));
		k=9;
		j=1;
		i=9;
		while(1)
		{
			if((N-k)<=0)
				break;
			N-=k;
			k*=i;
			i--;
			j++;
		}
		d=9;
		for(j1=j;j1>0;j1--,d--)
		{
			
			k=1;
			for(i=d;i>=11-j;i--)
				k*=i;
			if(j1==j)
				data[j1]=1;
			else
				data[j1]=0;
			while(1)
			{
				if(j1!=j)
				{					
					if((N-(data[j1]+1)*k)<=0)
						break;
				}
				else
				{
					if((N-(data[j1])*k)<=0)
						break;
				}
				data[j1]++;
			}
			if(j1!=j)
				N-=data[j1]*k;
			else
				N-=(data[j1]-1)*k;
			if(j1==j)
			{
				r=1;
				t=1;
				while(1)
				{
					if(r==data[j1])
					{
						while(flag[t]!=0)
						{
							t++;
						}
						flag[t]=1;
						data[j1]=t;
						break;
					}
					if(flag[t]==0)
					{
						r++;
						t++;
					}
					else
						t++;

				}
			}
			else
			{
				r=0;
				t=0;
				while(1)
				{
					if(r==data[j1])
					{
						while(flag[t]!=0)
						{
							t++;
						}
						flag[t]=1;
						data[j1]=t;
						break;
					}
					if(flag[t]==0)
					{
						r++;
						t++;
					}
					else
						t++;
				}
			}
		}
		for(i=j;i>0;i--)
			cout<<data[i];
		cout<<endl;
	}
	return 0;
}

 

27
26057

 

25
10000
0

 

For each input case, the program should print the nth repeatless number on a single line.

 

The input test file will contain multiple test cases, each consisting of a single line containing the integer n, where 1 ≤ n ≤ 1000000. The end-of-file is marked by a test case with n = 0 and should not be processed.

 

A repeatless number is a positive integer containing no repeated digits. For instance, the first 25 repeatless numbers are

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, …

Given an integer n, your goal is to compute the nth repeatless number.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值