HDU6033Add More Zero

来源:互联网 发布:淘宝新店旺旺提取神器 编辑:程序博客网 时间:2024/06/09 02:49

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6033


【题意】给定一个数字m,求出满足10^k<=2^m-1的最大的k。


【分析】对2^m取对数,然后求解该数以10为底数时幂即可,比赛时考虑多了加了精度判断,实际不会出现10^k=2^m的情况


【代码】

#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<map>#include<algorithm>#include<cmath>using namespace std;#define LL long long#define eps 1e-8#define PI acos(-1.0)int main(){    int m,cas=1;    while(~scanf("%d",&m)){        if(m==1){            printf("Case #%d: 0\n",cas++);            continue;        }        double tmp=m*log(2.0);        tmp/=log(10.0);        int ans=tmp;        if(tmp-ans<eps)            ans--;        printf("Case #%d: %d\n",cas++,ans);    }}

原创粉丝点击