日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > hdoj 1027 Ignatius and the Princess II 【逆康托展開】

hdoj 1027 Ignatius and the Princess II 【逆康托展開】

來源:程序員人生   發布時間:2014-11-04 08:23:38 閱讀次數:2182次

Ignatius and the Princess II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4865    Accepted Submission(s): 2929


Problem Description
Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5166 says, "I have three question for you, if you can work them out, I will release the Princess, or you will be my dinner, too." Ignatius says confidently, "OK, at last, I will save the Princess."

"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N⑴,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N⑴. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
 

Input
The input contains several test cases. Each test case consists of two numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume that there is always a sequence satisfied the BEelzebub's demand. The input is terminated by the end of file.
 

Output
For each test case, you only have to output the sequence satisfied the BEelzebub's demand. When output a sequence, you should print a space between two numbers, but do not output any spaces after the last number.
 

Sample Input
6 4 11 8
 

Sample Output
1 2 3 5 6 4 1 2 3 4 5 6 7 9 8 11 10
 
注意:由于1000的階乘太大,而且M小于等于10000,所以我們只需要算到階乘大于10000的為就能夠了,也就是8!。以后判斷是否是第8位的特殊判斷便可。

代碼:

#include <stdio.h> #include <string.h> int a[9] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320}; int vis[1005]; int main(){ int n, m; while(scanf("%d%d", &n, &m) == 2){ memset(vis, 0, sizeof(vis)); m -= 1; int cou, temp = 1; while(temp < n){ if((n - temp) <= 8){ int s = m/a[n-temp]; int p = m%a[n-temp]; int c = 0; for(int i = 1; i <= n; i ++){ if(!vis[i]) ++c; if((c⑴) == s){ printf("%d ", i); vis[i] = 1; break; } } m = p; } else{ for(int i = 1; i <= n; i ++){ if(!vis[i]) { vis[i] = 1; printf("%d ", i); break; } } } ++temp; } for(int i = 1; i <= n; i ++){ if(!vis[i]) printf("%d ", i); } } return 0; }




生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲一区二区三区四区五区六 | www99| 日本免费三区 | 国产精品久久久久久久久免费看 | 午夜精品久久久久 | 国产精品一区在线观看你懂的 | 久久精品欧美 | 成人在线免费毛片 | 91精品国产日韩91久久久久久 | 成人av观看 | 天堂成人国产精品一区 | 99精品综合 | 日韩视频精品在线 | 久久xx | 日韩精品 电影一区 亚洲 | 午夜精品久久久久久久久久蜜桃 | 亚洲二区免费 | 91精品国产九九九久久久亚洲 | 成年人午夜视频 | aaa免费看| 国产精品久久久一区二区三区 | 人操人人| 国产亚洲欧洲 | 久久精品国产亚洲一区二区三区 | 久久亚洲一区 | 国产精品电影在线观看 | 国产91精品久久久久久久 | 国产在线一区二区三区 | 精品日韩一区二区三区 | 久久久国产精品 | 日本大胆欧美 | 日韩精品一二三区 | 欧美精品久久久久久久 | 亚洲高清在线播放 | 日日夜夜精品视频免费 | 亚洲欧洲成人精品av97 | 国产在线精品一区二区三区 | 国产精品一区二区三区在线播放 | 成人免费网站在线观看 | 国产一区二区高清 | 日韩欧美黄色 |