您的位置:首页 > 其它

HDU6033 Add More Zero

2017-07-30 14:00 344 查看
题目连接: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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm