杭电acm上的2062求解答Problem DescriptionConsider the aggregate An=

杭电acm上的2062求解答
Problem Description
Consider the aggregate An= { 1, 2, …, n }. For example, A1={1}, A3={1,2,3}. A subset sequence is defined as a array of a non-empty subset. Sort all the subset sequece of An in lexicography order. Your task is to find the m-th one.

Input
The input contains several test cases. Each test case consists of two numbers n and m ( 0< n
cnhncgh 1年前 已收到1个回答 举报

遛马人 幼苗

共回答了14个问题采纳率:100% 举报

给你一个Testcase
Sample Input
11
Sample Output
20 71111
// 最小数远比你想想的复杂
#include
int main()
{
int n,m,bg,i;
while(scanf("%d",&n)==1)
{
m=n;
bg = 1;
while(m!=0)
{
if(m<=7)
{
switch(m)
{
case 2:printf("1"); break;
case 3:printf("7"); break;
case 4:printf("4"); break;
case 5:printf("2"); break;
case 6:if(bg) printf("6"); else printf("0"); break;
case 7:printf("8"); break;
}
m=0;
}
else
{
switch(m%7)
{
case 1:printf("10"); m-=8; break;
case 2:printf("1"); m-=2; break;
case 3:
case 4:
case 5:if(bg) else break;
case 6:if(bg) printf("6"); else printf("0"); m-=6; break;
case 0:printf("8"); m-=7; break;
}
}
bg = 0;
}
printf(" ");
if (n%2==0)
{
for (i=0;iprintf("1");
}
else
{
printf("7");
for (i=0;i<(n-3)/2;i++)
printf("1");
}
printf("n");
}
}

1年前

3
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.019 s. - webmaster@yulucn.com