Pku2856 我的第一百道题!

来源:互联网 发布:我的世界mac光影 编辑:程序博客网 时间:2024/06/03 01:13

一百道题目了,整个集训的末尾,我也达到了这个三位数,虽然不是很厉害,对我来说是另外的一个起点。开始向更低的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;elsedata[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;elseN-=(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++;}elset++;}}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++;}elset++;}}}for(i=j;i>0;i--)cout<<data[i];cout<<endl;}return 0;}

 

2726057

 

25100000

 

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.

原创粉丝点击