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);
}
}
【题意】给定一个数字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);
}
}
相关文章推荐
- 2017多校联合1(hdu6033)水Add More Zero
- HDU6033-2017多校第一场-Add More Zero
- 2017多校第一场 Add More Zero(hdu6033)
- HDU6033 Add More Zero【数学】
- (hdu6033)Add More Zero(数学,取对数)
- hdu6033 Add More Zero
- hdu6033--Add More Zero
- HDU6033-Add More Zero
- HDU6033---Add More Zero(2017多校联赛A题)
- 2017 Multi-University Training Contest - Team 1&hdu6033 Add More Zero
- HDU6033-Add More Zero
- 【HDU】6033 - Add More Zero(数学推导)
- Add More Zero HDU - 6033
- HDU 6033 Add More Zero(水~)
- Team 1——Add More Zero
- Add More Zero HDU - 6033
- HDU-多校训练赛-Add More Zero
- 17 多校1 Add More Zero 水题
- Add More Zero HDU - 6033
- HDU 6033 Add More Zero(取对数求一个数长度)