Floating-Point Numbers UVA - 11809
2018-03-06 23:52
411 查看
点击打开链接#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define bug(x) printf("***%d\n",x)
typedef long long ll;
using namespace std;
const double eps=1e-5;
ll B[50][50];
double A[50][50];
char s[100];
/*
5.699141892149156e76
9.205357638345294e18
0e0
*/
void get_table(){
for(int i=0;i<10;i++){
for(int j=1;j<=30;j++){
double m=1-pow(2,-1-i);
double e=(1<<j)-1;
double tmp=log10(m)+e*log10(2);
B[i][j]=(ll)(tmp);
A[i][j]=pow(10,tmp-B[i][j]);
}
}
}
void solve(double a,ll b){
for(int i=0;i<10;i++){
for(int j=1;j<31;j++){
if(b==B[i][j]&&fabs(a-A[i][j])<=eps){
printf("%d %d\n",i,j);return ;
}
}
}
}
int main()
{
get_table();
while(scanf("%s",s)==1){
if(!strcmp(s,"0e0")) break;
*(strchr(s,'e'))=' ';//太优秀了
double a;ll b;
sscanf(s,"%lf %lld",&a,&b);
//printf("%.2f %lld\n",a,b);
solve(a,b);
}
return 0;
}
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define bug(x) printf("***%d\n",x)
typedef long long ll;
using namespace std;
const double eps=1e-5;
ll B[50][50];
double A[50][50];
char s[100];
/*
5.699141892149156e76
9.205357638345294e18
0e0
*/
void get_table(){
for(int i=0;i<10;i++){
for(int j=1;j<=30;j++){
double m=1-pow(2,-1-i);
double e=(1<<j)-1;
double tmp=log10(m)+e*log10(2);
B[i][j]=(ll)(tmp);
A[i][j]=pow(10,tmp-B[i][j]);
}
}
}
void solve(double a,ll b){
for(int i=0;i<10;i++){
for(int j=1;j<31;j++){
if(b==B[i][j]&&fabs(a-A[i][j])<=eps){
printf("%d %d\n",i,j);return ;
}
}
}
}
int main()
{
get_table();
while(scanf("%s",s)==1){
if(!strcmp(s,"0e0")) break;
*(strchr(s,'e'))=' ';//太优秀了
double a;ll b;
sscanf(s,"%lf %lld",&a,&b);
//printf("%.2f %lld\n",a,b);
solve(a,b);
}
return 0;
}
相关文章推荐
- UVA - 11809 Floating-Point Numbers
- UVA - 11809 Floating-Point Numbers
- 算法竞赛入门经典第三章3-12 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
- UVA - 11809 Floating-Point Numbers
- UVa 11809:Floating-Point Numbers
- UVa-11809 - Floating-Point Numbers
- UVa 11809 - Floating-Point Numbers
- UVa11809 - Floating-Point Numbers
- UVa 11809 Floating-Point Numbers
- 习题3-12 浮点数(Floating-Point Numbers, UVa11809)
- Uva 11809 Floating-Point Numbers
- UVA-11809 Floating-Point Numbers
- UVA 11809 - Floating-Point Numbers【浮点数】