CodeForces 618A Slime Combining

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.

Examples
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 2 1.

In the last sample, the steps look as follows:

  1. 1
  2. 2
  3. 2 1
  4. 3
  5. 3 1
  6. 3 2
  7. 3 2 1

  1. 4

观察,寻找规律!
AC代码:
   
#include<stdio.h>
int a[20];
void db()
{
	a[0]=1;
	for(int i=1;i<20,a[i-1]<100000;i++)
	{
		a[i]=a[i-1]*2;
	}
}
int main()
{
	db();
	int n;
	int i,j;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<20;i++)
		{
			if(a[i]>n)
			{
				printf("%d ",i);
				n-=a[i-1];
				i=-1;
			}
			else if(a[i]==n)
			{
				printf("%d\n",i+1);
				break;
			}
		}
	}
	return 0;
 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Table of Contents 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.1 2.2 Supported Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Downloading SLIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.1 Downloading from Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2.2 Git incantations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3.1 Installing from Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Running SLIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5 Setup Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5.1 Basic customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5.2 Multiple Lisps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5.3 Loading Swank faster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 2 2 3 3 3 3 4 4 4 5 Using Slime mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1 User-interface conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.1 Temporary buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.2 *inferior-lisp* buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.3 Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1.4 Key bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Evaluation commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Compilation commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.4 Completion commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.5 Finding definitions (“Meta-Point” commands). . . . . . . . . . . . . . . . . 10 3.6 Documentation commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.7 Cross-reference commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.7.1 Xref buffer commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.8 Macro-expansion commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.9 Disassembly commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.10 Abort/Recovery commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.11 Inspector commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.12 Profiling commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.13 Shadowed Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.14 Semantic indentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.15 Reader conditional fontification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4 SLDB: the SLIME debugger. . . . . . . . . . . . . . . . . . 17 4.1 4.2 4.3 4.4 4.5 Examining frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invoking restarts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Navigating between frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Miscellaneous Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 17 18 18 19ii 5 Misc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.1 slime-selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.2 slime-macroexpansion-minor-mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.3 Multiple connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6 Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 6.1 Emacs-side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.1 Hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Lisp-side (Swank) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.1 Communication style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.2 Other configurables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 7.1 Connecting to a remote lisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.1 Setting up the lisp image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.2 Setting up Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.3 Setting up pathname translations . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Globally redirecting all IO to the REPL . . . . . . . . . . . . . . . . . . . . . . . 7.3 Connecting to SLIME automatically . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 23 23 24 24 25 27 27 28 28 28 29 Contributed Packages . . . . . . . . . . . . . . . . . . . . . . . . . 30 8.1 Loading Contrib Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.1.1 Loading and unloading “on the fly” . . . . . . . . . . . . . . . . . . . . . . . 8.2 REPL: the “top level”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.1 REPL commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.2 Input navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2.3 Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3 Multiple REPLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4 inferior-slime-mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5 Compound Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6 Fuzzy Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6.1 The Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6.2 Duplicate Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.7 slime-autodoc-mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8 ASDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.9 Banner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.10 Editing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.11 Fancy Inspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.12 Presentations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13 Typeout frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.14 TRAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15 Documentation Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.16 Xref and Class Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.17 Highlight Edits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.18 Scratch Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.19 SLIME Trace Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.20 slime-sprof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.21 Meta package: slime-fancy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 30 30 31 32 32 33 33 34 35 35 35 36 37 38 38 38 39 41 41 41 42 42 42 42 45 45iii 9 Credits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Hackers of the good hack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Thanks! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Key (Character) Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Command and Function Index . . . . . . . . . . . . . . . . . . . 50 Variable and Concept Index . . . . . . . . . . . . . . . . . . . . . . 52
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值