【习题 3-12 UVA - 11809】Floating-Point Numbers
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
$A*10^B = temp[M]*2^{2^E-1}$
两边取一下对数
得到
$lg_A+B = lg_{temp[M]} + (2^E-1)*lg_2$
这样就不至于算不出来啦。
打个表就好
防止爆精度。
加个long double.
【代码】
#include <bits/stdc++.h>
using namespace std;
string s;
long double two[20];
long double temp[20];
long long temp2[70];
long double ans[100][100];
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
two[1] = 0.5;
for (int i = 2;i <= 12;i++){
two[i] = two[i-1]*0.5;
}
temp[0] = two[1];
for (int i = 1;i <= 9;i++) temp[i] = temp[i-1] + two[i+1];
temp2[0] = 1;
for (int i = 1;i <= 30;i++) temp2[i] = temp2[i-1] * 2;
for (int i = 0;i <= 9;i++){
double M = temp[i];
for (int j = 1;j <= 30;j++){
ans[i][j] = log10(M) + (temp2[j]-1)*log10(2);
}
}
while (cin >> s){
int len = s.size();
for (int i = 0;i < len;i++) if (s[i]=='e') s[i] = ' ';
long double A;
long long B;
stringstream ss(s);
ss >> A >> B;
if (A==0 && B==0) break;
double temp = log10(A)+B;
bool fi = false;
for (int i = 0;!fi && i <= 9;i++)
for (int j = 1;!fi && j <= 30;j++)
if (fabs(ans[i][j]-temp)<1e-6){
printf("%d %d\n",i,j);
fi = true;
}
}
return 0;
}
【习题 3-12 UVA - 11809】Floating-Point Numbers的更多相关文章
- 最小正子序列(序列之和最小,同时满足和值要最小)(数据结构与算法分析——C语言描述第二章习题2.12第二问)
#include "stdio.h" #include "stdlib.h" #define random(x) (rand()%x) void creat_a ...
- uva 10712 - Count the Numbers(数位dp)
题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是 ...
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- UVA 11809 - Floating-Point Numbers
数学太渣了,这道题反复参考了大神的博客,算是看懂了吧.博客原文 http://blog.csdn.net/crazysillynerd/article/details/43339157 算是个数学题 ...
- 【每日一题】 UVA - 11809 Floating-Point Numbers 阅读题+取对数处理爆double
https://cn.vjudge.net/problem/UVA-11809 题意:很长orz 题解:算一下输入范围,发现用double是读不进来的,在这里wa了半天,(double 1e300 ...
- UVA 11481 - Arrange the Numbers 数学
Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You ca ...
- 【UVA - 136】Ugly Numbers(set)
Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- UVA 10539 - Almost Prime Numbers 素数打表
Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...
- comparison of floating point numbers with equality operator. possible loss of precision while rounding values
double值由外部传入 private void Compare(double value) { string text; ) //小数位后保留2位 { //小数点后保留2位小数 text = st ...
随机推荐
- OCP-1Z0-051-题目解析-第26题
26. Which is the valid CREATE TABLE statement? A. CREATE TABLE emp9$# (emp_no NUMBER (4)); B. CRE ...
- 路由及路由器工作原理深入解析3:路由与port
日志"路由及路由器工作原理深入解析1"http://user.qzone.qq.com/2756567163/blog/1438322342介绍了"为什么要使用路 ...
- jquery16 DOM操作 : 添加 删除 获取 包装 DOM筛选
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- js---17继承中方法属性的重写
function F(){}; var f = new F(); f.name = "cf"; f.hasOwnProperty("name");//true ...
- 74.QT窗口实现类的封装
#include "mainwindow.h" #include <QApplication> #include <windows.h> //定义一个窗口类 ...
- rune 切片 go
package main import ( "fmt" ) func main() { var s = "go程序``**//;;''[p]=-\\&|@#$%^ ...
- Oracle与MySQL的转化差异
1.nvl函数. Oracle 中 : nvl (join_count , 0) MySQL中:if(join_count is null,'0',join_count) ...
- python中lambda的另类使用
带if/else: ( lambda x, y: x if x < y else y )( 1, 2 ) 科里化: ( lambda x: ( lambda y: ( lambda z: x + ...
- 20亿与20亿表关联优化方法(超级大表与超级大表join优化方法)
记得5年前遇到一个SQL.就是一个简单的两表关联.SQL跑了几乎相同一天一夜,这两个表都非常巨大.每一个表都有几十个G.数据量每一个表有20多亿,表的字段也特别多. 相信大家也知道SQL慢在哪里了,单 ...
- Harry Potter and the Goblet of Fire
书名:Harry Potter and the Goblet of Fire 作者:J.K. Rowling 篇幅: 752页 蓝思值:880L 用时: 17天 工具: 有道词典 [透析成果 ...