水题,贪心,dp都随意
1 /* 2 author:jxy 3 lang:C/C++ 4 university:China,Xidian University 5 **If you need to reprint,please indicate the source** 6 */ 7 #include <iostream> 8 #include <cstdio> 9 #include <cstdlib> 10 #include <cstring> 11 #include <algorithm> 12 using namespace std; 13 int dp[10005]; 14 void pre()//dp用 15 { 16 memset(dp,123,sizeof(dp)); 17 dp[1]=0; 18 int Max=10001,i,j; 19 for(i=1;i<=Max;i++) 20 for(j=1;j<=i&&i+j<=Max;j++) 21 dp[i+j]=min(dp[i+j],dp[i]+1); 22 } 23 int main() 24 { 25 int n,C=0; 26 // pre(); 27 while(~scanf("%d",&n)&&n>=0) 28 printf("Case %d: %d\n",++C,n==1?0:(int)log2(n-1)+1); 29 }
原文:http://www.cnblogs.com/czjxy881/p/3536600.html