Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:原理

Posted by 317358117 at 2010-09-01 18:57:23 on Problem 2453
In Reply To:原理 Posted by:huicpc0860 at 2010-04-07 20:50:24
这个方法我也想到了,不过不会位运算。。暴力水果的,,太菜了...小证明下原理

由题目要求可知原二进制中必然有1位1向左移动一位,这样可以使原数增大,要想使原数增大的幅度最小,一定要将移动这位的后面所有的1放到最后紧密排列才可以,这样可以保证增大的幅度最小

假设n的二进制如下abcdef.......共S位,假设第i位为0 i+1位为1,那么将第i+1位的1转移到第i位,则原数增大了2^(S-i)-2^(S-i-1)=2^(S-i-1),同时将i+1位后面的1在末尾紧密排列,更能缩小增幅。。所以增幅随着i的增大而减小,写代码就是楼上的那个。。。::>_<::

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator