多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

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

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

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

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; }




生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲 欧美 日韩中文字幕一区二区 | 波多野结衣午夜 | 日韩欧美亚洲一区二区综合 | 国产精品vs欧美精品 | 男人天堂国产 | 在线看日本a毛片 | 久久久久嫩草影院精品 | 日本一区二区三区不卡在线视频 | 好好的曰www视频在线观看 | 欧美日韩一二 | 亚洲综合久久1区2区3区 | 亚洲欧美综合图片 | 免费看成人毛片日本久久 | 欧美黑人xxxx猛牲大交 | 福利亚洲| 最近中文在线中文 | 美美女高清毛片视频黄的一免费 | 欧美亚洲国产一区二区三区 | 亚洲伊人久久大香线蕉影院 | 欧美99热 | 伊人影院视频 | 欧美日韩成人在线观看 | 日韩免费一区 | 午夜视频免费 | 亚洲欧美综合图片 | 久久丝袜精品综合网站 | 欧美一级毛片久久精品 | 日韩 欧美 自拍 | 国产婷婷一区二区在线观看 | 日韩精品一区二区三区在线观看l | 色中色在线视频 | 国产亚洲精品色一区 | 亚洲国产欧美在线人成精品一区二区 | 欧美日韩aa一级视频 | 亚洲日本免费 | 亚洲性夜夜时 | 自拍偷拍二区 | 岛国午夜精品视频在线观看 | 亚洲国产成人精品一区二区三区 | 欧美精品一区二区三区久久 | 性生活免费视频网站 |