【习题 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 ...
随机推荐
- GridControl添加右键菜单
private void gridView1_MouseDown(object sender, MouseEventArgs e) { GridHitInfo vi = gridView1.CalcH ...
- JS中的onload与jQuery中的ready差别
jQuery的运行机制(onload与ready的差别) 结论得出前自行測试: 为了測试是否真如所说的那样,所以在页面插入了20000张照片,照片数量少得不出什么结论,所以改用console.log( ...
- es62
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 洛谷P2251 质量检测
题目背景 无 题目描述 为了检测生产流水线上总共N件产品的质量,我们首先给每一件产品打一个分数A表示其品质,然后统计前M件产品中质量最差的产品的分值Q[m] = min{A1, A2, ... Am} ...
- 【基础篇】EditText的一些属性设置
设置EditText的背景颜色 private test_editText=null; test_editText= (EditText) findViewById(R.id.EditTextInp ...
- array01.js
//1.获取指定范围内的随机数 function getRadomNum(min,max){ return Math.floor(Math.random() * (max - min + 1)) + ...
- 用node.js从零开始去写一个简单的爬虫
如果你不会Python语言,正好又是一个node.js小白,看完这篇文章之后,一定会觉得受益匪浅,感受到自己又新get到了一门技能,如何用node.js从零开始去写一个简单的爬虫,十分钟时间就能搞定, ...
- 【Educational Codeforces Round 36 A】 Garden
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举用哪一个桶就好 [代码] #include <bits/stdc++.h> using namespace std; ...
- BZOJ 3675 APIO2014 序列切割 斜率优化DP
题意:链接 方法:斜率优化DP 解析:这题BZ的数据我也是跪了,特意去网上找到当年的数据后面二十个最大的点都过了.就是过不了BZ. 看到这道题自己第一发DP是这么推得: 设f[i][j]是第j次分第i ...
- Axios再记录
一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端(可实现ajax的请求) 有关学习网址:https://www.tuicool.com/articles/eMb2yuY ...