UVA - 11809 Floating-Point Numbers
来源:互联网 发布:java 设计模式 书籍 编辑:程序博客网 时间:2024/04/29 09:21
//
第三章的最后一道题, 当时没敢看, 也是醉了。 后来ACM群里讨论了, 有点印象, 现在仔细看也不是很难。
//
1、那个样例的第二个A(算法入门)是0.5*1+0.5/2+0.5/2/2 +0.5/...2(除八个二), 这是计算机的储存方式。 仅仅知道这里而已。
2.INF要取到10的-4-6都行, 但是10的-10不行。
3.两边对数, 打表, 直观。
<pre name="code" class="cpp">#include <iostream>#include <cstdio>#include <string.h>#include<math.h>#include<algorithm>const int maxn = 30 + 5;const double INF = 1e-6;using namespace std;const int E[maxn] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383,32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431,67108863, 134217727, 268435455, 536870911, 1073741823};const double M[maxn] = {0.5, 0.75, 0.875, 0.9375,0.96875, 0.984375, 0.9921875, 0.99609375, 0.998046875,0.9990234375, 0.99951171875};char str[maxn];int main(){ while(scanf("%s", str) && strcmp(str, "0e0") != 0) { *(strchr(str, 'e')) = ' '; int EE, B; double MM, A, BB; sscanf(str, "%lf %d", &A, &B); BB = log10(A) + B; for(int i = 0; i <= 9; i++) { for(int j = 1; j <= 30; j++) { if(fabs( (log10(M[i]) + E[j] * log10(2)) - BB) < INF) { printf("%d %d\n", i, j); break; } } } } return 0;}
0 0
- 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-11809Floating-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
- UVa 11809:Floating-Point Numbers
- UVa 11809 Floating Point Numbers
- UVa 11809 Floating-Point Numbers
- 编写Linux Shell脚本相关知识
- 如何用unity3D编辑英雄技能冷切框
- bzoj2002:[Hnoi2010]Bounce 弹飞绵羊
- [转载]二叉树的非递归遍历方法
- 背包问题
- UVA - 11809 Floating-Point Numbers
- 【VB与数据库】机房收费系统设计阶段之上下机
- 躲猫猫!验证机制隐藏在API中
- C++获取系统时间
- Linux_4.5_信号通讯编程
- 【VB与数据库】机房收费系统设计阶段之结账
- [FLAG]想要写但是还没写的题解
- Mybatis深入之事务管理
- 调试spark源码