UVa 11809 浮点数
来源:互联网 发布:淘宝卖家咨询客服电话 编辑:程序博客网 时间:2024/04/28 17:47
题意:给定最大浮点数,求阶码和尾数
题目很简单,可惜对浮点数不了解
k位尾数对应1-2^(-k-1)=a
k位阶码对应2^(2^k-1)=b
a*2^b=m*n^10
取对数得lg(a)+lg(2)*b=lg(m)+n;
令左式=x
则得x=lg(m)+n;
易证n=floor(x);
则m=10^x/10^n=10^(x-n);
我们可以打表记录然后查询
代码如下:
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long LL;
double M[10][31],a,c,x;
LL E[10][31],b,d;
char s[30];
double p;int q,i,j;
int main()
{
/*打表*/
for(i=0;i<=9;i++)
for(j=1;j<=30;j++){
a=1-pow(2,-(i+1));b=pow(2,j)-1;x=log10(a)+b*log10(2);d=floor(x);c=pow(10,x-d);
M[i][j]=c;E[i][j]=d;
}
while(cin>>s){
if(s=="0e0")
break;
s[17]=' ';
sscanf(s,"%lf %d",&p,&q);//懒惰万岁!
for(i=0;i<10;i++)
for(j=1;j<=30;j++)
if(fabs(M[i][j]-p)<1e-4&&E[i][j]==q)//查表
printf("%d %d\n",i,j);
}
return 0;
}
- UVa 11809 浮点数
- UVa 11809 Floating-Point Numbers (浮点数)
- UVA 11809 - Floating-Point Numbers【浮点数】
- 题解:浮点数(UVa 11809)
- UVa 11809 Floating-Point Numbers(浮点数)
- 浮点数-UVa-做题反思
- UVA 465 - Overflow (浮点数的优势)
- uva 748 Exponentiation 浮点数乘方运算 高精度水题
- UVA 465 Overflow(浮点数的范围)
- 浮点数
- 浮点数
- 浮点数
- 浮点数
- 浮点数
- 浮点数
- 浮点数
- 浮点数
- 浮点数
- unity3d的四元数 Quaternion
- hdu 2196 树形dp
- C++ HOJ 约瑟夫问题 的 数组、链表及STL实现
- 显示mysql查询错误信息, mysql_query($sql) or die(mysql_error());
- Xcode7中关于下载网络图片报错的问题
- UVa 11809 浮点数
- Java多线程之生产者消费者模式
- springmvc批量文件打包成zip下载功能
- 线程安全的SRILM语言模型c++接口
- html5 canvas自定义画板
- bestcoder 48# wyh2000 and a string problem (水题)
- 66 报送验证函数问题与解决 each()方法
- java导出excel表格,Struts2配置
- iOS开发中@property的属性介绍