UVa11809

【题目描述】

传送门

【题目分析】

终于把这道题做完了,之前一直连题意都看不懂。实在不行上网找了一下大佬的博客,看懂题意后自己写,发现读入很难处理,就又学习了一下大佬的读入方法,用的是C++里面的sstream,很巧妙。

主要就是一个打表。因为数据情况很少而且给定,所以打表就能解决。

还需要注意用到两边取对数,因为阶码部分的位数很大,根本不可能存下。

【AC代码】

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<sstream>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=35;
const double EPS=1e-6;
double A;
int B;

int rnk[MAXN][MAXN];
int tot=0;
struct node
{
    int M,E;
    ll B;
    double A;
}a[MAXN*MAXN];

ll quick_pow(ll a,ll b)
{
    ll ret=1;
    while(b)
    {
        if(b%2) ret*=a;
        a*=a;
        b/=2;
    }
    return ret;
}

const double LOG2=log10(2.0);

void init()
{
    for(int i=0;i<=9;i++)
    {
        for(int j=1;j<=30;j++)
        {
            int tmp=quick_pow(2,1+i);
            double x=log10(tmp-1)-log10(tmp);
            double y=x+(quick_pow(2,j)-1)*LOG2;
            a[tot].M=i; a[tot].E=j;
            a[tot].B=(ll)(y);
            a[tot].A=pow(10,y-a[tot].B);
            tot++;
        }
    }
}

int main()
{
    init();
    string in;
    while(cin>>in && in!="0e0")
    {
        
        for(string::iterator i=in.begin();i!=in.end();i++)
        {
        	if(*i=='e')
        	{
        		*i=' ';
        		break;
			}
		}
		stringstream ss(in);
		ss>>A>>B;
		for(int i=0;i<tot;i++)
		{
			if(fabs(a[i].A-A)<EPS && a[i].B==B)
			{
				printf("%d %d\n",a[i].M,a[i].E);
				break; 
			}
		}
    }
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值