joj 2045: Mountains

2045: Mountains

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
1s 8192K 79 37 Standard

A mountain consists of one or more hills, each of which consists of upwards, which we denote with `/', and downwards, which we denote with '/'. We call upwards and downwards together as wards. Let /n be an upward of length n, and in the same way, let /n be a downward of length n. For example, the following upward is /2:

 /
/

and the following downward is /3:

/
 /
  /

The set of all hills is given in the following:

Hills =def { /n/n | n is a natural number }

Now it comes to the definition of a mountain(in BNF):

Mountain ::= Hill | Mountain Mountain

That's to say, a hill is a mountain, and if M and N are mountains, then the concatenation of M and N is also a mountain.

For example,

     //
/////  /

is a mountain with 3 hills.

We define the width of a mountain as the number of upwards and downwards. We define the height of a mountain as the maximum length of upwards(or equivalently downwards).

We can give each mountain a unique number, called index, such that the following conditions are met:

  1. index begins with 1
  2. the index of a mountain with larger width is larger
  3. if two mountains have the same width, then the index of the mountain whose leftmost different ward with the other mountain is an upward is larger

For example, portion of the mountains and their indices are:

                 //                    //                   //         //
//     ////     /  /     //////     ///  /     ...     /////  /     ///  ///     ...

1       2        3         4          5                   9            10

In this problem, you are print the mountain from the given index.

Input

The input contains several lines, each of which contains an integer N<2^32. The last line contains 0, which you should not proceed.

Output

For each N, your program should print the mountain. For simplicity, you needn't make the mountain climbing. You can imagine that the mountain finally printed is the one after being flattened. For example, for N=9, your program should simply print:

////////

.

Each mountain should be printed in a single line.

Sample Input

6
9
0

Sample Output

//////
//////// 

 

Problem Source: siyee

 

This problem is used for contest: 9  171   

 

/* 每个宽度所对应的山峰的数目和相同位数对应的二进制数目相同,并且山峰的比较方式和二进制比较方式也是对应的 1001 左边连续一个1,有一个山峰,为// 接着将1后面的0改为1,得101,又只有一个连续的山峰,为// 接着将1后面的0改为1,得11,有两个连续的山峰,为//// 则为//////// */ #include<cstdio> #include<cstring> int a[50]; int main() { unsigned int n; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(a,0,sizeof(a)); if(n==0) break; int num=0; while(n>0) { a[++num]=n&1; n=n>>1; } for(int i=num;i>=1;) { int t=0; while(a[i]==1&&i>=1) { t++; i--; } for(int j=1;j<=t;j++) printf("/"); for(int j=1;j<=t;j++) printf("//"); a[i]=1; } printf("/n"); } return 0; }  

你可能感兴趣的:(joj 2045: Mountains)