uva11384Help is needed for Dexter<二分>

链接:http://uva.onlinejudge.org/external/113/11384.html

题意:

给定正整数n,你的任务是用最少的操作次数把序列1, 2, …, n中的所有数都变成0。每次操作可从序列中选择一个或多个整数,同时减去一个相同的正整数;

思路:

简单的二分;

 

View Code
 1 #include <stdio.h>
 2 int N;
 3 int main( )
 4 {
 5     while( scanf( "%d", &N )!= EOF ){    
 6         if( N>1 ){
 7             int ans=0;
 8             while( N ){
 9                 N>>=1, ans++;
10             }
11             printf( "%d\n", ans );    
12         }
13         else puts( "1" );
14     }
15     return 0;
16 }

 

 

 

 

posted @ 2013-01-14 16:35  淡墨æ末央  阅读(153)  评论(0编辑  收藏  举报