您的位置:首页 > 其它

Wunder Fund Round 2016 A. Slime Combining

2016-01-30 11:56 274 查看
A. Slime Combining

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.

You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes
one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v,
you combine them together to create a slime with value v + 1.

You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in
the row from left to right.

Input

The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).

Output

Output a single line with k integers, where k is
the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers
should be the value of the i-th slime from the left.

Sample test(s)

input
1


output
1


input
2


output
2


input
3


output
2 1


input
8


output
4


Note

In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.

In the second sample, we perform the following steps:

Initially we place a single slime in a row by itself. Thus, row is initially 1.

Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with
value 2. Thus, the final state of the board is 2.

In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 21.

In the last sample, the steps look as follows:

122 13
3 13 23 2 14
题意:给你n个泥巴,摆成一行,摆的时候最右边两个值一样时两个就合并,并且值+1.

例如:n=3,第一次:1;第二次:1 1;值一样,合并为2,第三次:2  1;最后结果就为2   1.
     又如n=8:

12 (原为1 1,合并)
2 13 (原为2 1 1,合并 2 2 ,再合并 3)
3 13 2 (原为3 1 1,合并3 2)
3 2 14 (原为 3 2 1 1,合并3 2 2,合并3 3,合并 4)

思路:这里其实有个规律,输出的是n的二进制数1对应的位置下标(从右往左),如3,二进制为11,输出就为2 1;
如8,二进制为1000,输出就为4,如7,二进制为111,输出就为3 2 1……
关键还是看懂题后找规律。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define inf 0x3f3f3f3f

int main()
{
int n;
while(cin >> n){
for (int i = 16; i >=0; --i)
if (n & (1 << i))cout << i + 1 << " ";
cout << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: