【題目描述】
傳送門
【題目分析】
終于把這道題做完了,之前一直連題意都看不懂。實在不行上網找了一下大佬的博客,看懂題意后自己寫,發現讀入很難處理,就又學習了一下大佬的讀入方法,用的是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;
}