POJ 1781

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
unsigned fun(unsigned num);
int main()
{
    //freopen("acm.acm","r",stdin);
    string s;
    unsigned num;
    unsigned i;
    while(cin>>s,s != "00e0")
    {
        num = 0;
        num += (s[0]-'0')*10;
        num += s[1]-'0';
        num *= pow((double)10,(double)(s[3]-'0'));
        i = fun(num);
//        cout<<i<<"  **********8  "<<endl;
    //    cout<<"num "<<num<<endl;
    //            cout<<i<< "    8888888888888888 "<<endl;
        i = -(1-pow((double)2,double(i-1)));
        num -= i;
        unsigned j = 1;
    //    cout<<"num  "<<num<<endl;
        for(i = 0; i < num-1; ++ i)
        {
            j += 2;
        //    cout<<j<<" ";
        }
    //    cout<<endl;
        cout<<j<<endl;
    }
}

unsigned fun(unsigned num)
{
    unsigned i = 0;
    unsigned sum;
    sum = -(1-pow((double)2,(double)(i-1)));
    while(sum < num)
    {
        ++ i;
        sum = -(1-pow((double)2,double(i-1)));
    }
    return i-1;
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

原文地址:https://www.cnblogs.com/gavinsp/p/4566547.html