UVa 11809 第三张最后一个题目。http://blog.csdn.net/crazysillynerd/article/details/43339157

来源:互联网 发布:北京电子科技学院 知乎 编辑:程序博客网 时间:2024/05/07 11:04

        http://blog.csdn.net/crazysillynerd/article/details/43339157 

    起初我也不会,看了这个文章后,思路上受到启发,解释很详细了。

   

      我自己用c写了 一些代码简洁上的优化。可能更容易看懂一些。

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
int main(){
    //freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
      double A,B,zuo,you,k;
      double M[10],E[31];
             M[0] = 0.5;
            for (int i=1; i<=9 ;i++)
                 M[i] = M[i-1] + pow(2,-(i+1));


             for (int i=1; i<= 30 ; i++)
                    E[i] = pow(2,i) - 1;

//预处理部分。思路的话可以看上面的文章 很详细了。
      while (scanf("%17lfe%lf",&A,&B)==2 ){
    //%17f 读入占17长度,正好是前面的一部分  然后 读入e  然后读入后面的指数


              for (int i = 0; i< 10 ; i++)
                for (int j = 1 ; j<=30 ; j++){
                      int flag = 1;
                       you = log10(M[i]) + E[j]*log10(2);
                    if (flag && fabs(log(A)+B - you )<0.00001) {
                        flag = 0;
                        printf("%d %d\n",i,j);
                    }
                }
     }
}


1 0
原创粉丝点击