UVA11809 - Floating-Point Numbers
2015-03-09 19:23
330 查看
做个结构体,M存位数 和 E存阶码
然后 匹配数据即可
然后 匹配数据即可
#include <cstdio> #include <cmath> #include <cstring> typedef long long ll; const double min_differ=1e-5; struct{ double M; //存储对应尾数 ll E; //存储对应指数 }po[11][33]; void solve(double m,ll e){ for(int i=0;i<=9;i++) for(int j=1;j<=30;j++) if(e==po[i][j].E&&fabs(m-po[i][j].M)<min_differ){ printf("%d %d\n",i,j); return; } } int main(){ int i,j; double m,t; ll e; char str[22]; for(i=0;i<=9;i++) for(j=1;j<=30;j++){ e=(1<<j)-1; //1 11 111 1111 -> 1*(10) m=1-1.0/(1<<(i+1)); t=log10(m)+e*log10(2); po[i][j].E=t/1; po[i][j].M=pow(10,t-po[i][j].E); } while(scanf("%s",str),strcmp(str,"0e0")){ *(strchr(str,'e'))=' '; sscanf(str,"%lf %lld",&m,&e); solve(m,e); } return 0; }
相关文章推荐
- UVa11809-Floating-Point Numbers
- UVA 11809 Floating-Point Numbers(暴力)
- UVa 11809 Floating-Point Numbers
- UVA - 11809 Floating-Point Numbers
- UVa-11809 - Floating-Point Numbers
- UVA - 11809 Floating-Point Numbers
- UVa 11809 Floating-Point Numbers (浮点数)
- UVa-11809 - Floating-Point Numbers
- uva 11809 Floating-Point Numbers
- UVA-11809 Floating-Point Numbers
- 【习题 3-12 UVA - 11809】Floating-Point Numbers
- UVA 11809 - Floating-Point Numbers
- 算法竞赛入门经典(紫书)第三章——Floating-Point Numbers UVA-11809
- uva - 11809 - Floating-Point Numbers
- UVa 11809 Floating-Point Numbers
- UVA - 11809 Floating-Point Numbers
- UVA 11809 Floating-point numbers
- UVA 11809 Floating-Point Numbers
- UVA - 11809 Floating-Point Numbers
- UVa 11809:Floating-Point Numbers