您的位置:首页 > 其它

Floating-Point Numbers UVA - 11809

2018-03-06 23:52 411 查看
点击打开链接#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define bug(x) printf("***%d\n",x)
typedef long long ll;
using namespace std;

const double eps=1e-5;
ll B[50][50];
double A[50][50];
char s[100];
/*
5.699141892149156e76
9.205357638345294e18
0e0
*/
void get_table(){
for(int i=0;i<10;i++){
for(int j=1;j<=30;j++){
double m=1-pow(2,-1-i);
double e=(1<<j)-1;
double tmp=log10(m)+e*log10(2);
B[i][j]=(ll)(tmp);
A[i][j]=pow(10,tmp-B[i][j]);
}
}
}

void solve(double a,ll b){
for(int i=0;i<10;i++){
for(int j=1;j<31;j++){
if(b==B[i][j]&&fabs(a-A[i][j])<=eps){
printf("%d %d\n",i,j);return ;
}
}
}
}

int main()
{
get_table();
while(scanf("%s",s)==1){
if(!strcmp(s,"0e0")) break;
*(strchr(s,'e'))=' ';//太优秀了
double a;ll b;
sscanf(s,"%lf %lld",&a,&b);
//printf("%.2f %lld\n",a,b);
solve(a,b);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: