• (Incomplete)UVa 701 The Archeologist's Dilemma


    方法:对数,暴力

    我们需要求出最小的e,是的存在一个i > len(n) , 满足   floor[2^e/ (10^i)]= n, 即 n*10^i < 2^e < (n+1)*10^i。对两边同时取log10 (以10为底的对数,记作lg),得到

    lg(n) + i < e*lg(2) < lg(n+1) + i。 注意len(n) = (int) lg(n)+1, 之前一个条件 i > len(n) 可以转化为 i > lg(n)+1,  然后暴力枚举即可。 注意2的power有无限个,无解的情况不存在(待考证)。

    code:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <vector>
    #include <stack>
    #include <bitset>
    #include <cstdlib>
    #include <cmath>
    #include <set>
    #include <list>
    #include <deque>
    #include <map>
    #include <queue>
    #include <fstream>
    #include <cassert>
    #include <unordered_map>
    #include <cmath>
    #include <sstream>
    #include <time.h>
    #include <complex>
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    #define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
    #define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
    #define DFOR(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
    #define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
    #define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
    #define FOREACH(a,b) for (auto &(a) : (b))
    #define rep(i,n) FOR(i,0,n)
    #define repn(i,n) FORN(i,1,n)
    #define drep(i,n) DFOR(i,n-1,0)
    #define drepn(i,n) DFOR(i,n,1)
    #define MAX(a,b) a = Max(a,b)
    #define MIN(a,b) a = Min(a,b)
    #define SQR(x) ((LL)(x) * (x))
    #define Reset(a,b) memset(a,b,sizeof(a))
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define ALLA(arr,sz) arr,arr+sz
    #define SIZE(v) (int)v.size()
    #define SORT(v) sort(all(v))
    #define REVERSE(v) reverse(ALL(v))
    #define SORTA(arr,sz) sort(ALLA(arr,sz))
    #define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
    #define PERMUTE next_permutation
    #define TC(t) while(t--)
    #define forever for(;;)
    #define PINF 1000000000000
    #define newline '
    '
    
    #define test if(1)if(0)cerr
    using namespace std;
      using namespace std;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef pair<int,int> ii;
    typedef pair<double,double> dd;
    typedef pair<char,char> cc;
    typedef vector<ii> vii;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll> l4;
    const double pi = acos(-1.0);
    
    int n;
    int solve()
    {
        int i = log10(n)+2;
        for (;;++i)
        {
            int a = (log10(n) + i)/log10(2), b = ceil((log10(n+1)+i)/log10(2));
            
            if (a+1 < b)
                return a+1;
        }
        return -1;
    }
    
    int main()
    {
        while (cin >> n)
        {
            cout << solve() << newline;
        }
    }
    /*
     
     0 0 0 0
     0 0 0 100
     5 20 34 325 4 5 6 7
     283 102 23 320 203 301 203 40 -1 -1 -1 -1
    */
    

      

  • 相关阅读:
    软件工程课感想
    冲刺阶段(二)第五天 5月19日
    CATransition转场动画
    UIView与CALayer的区别
    CALayer的基本属性
    CALayer的基本属性和contexts的内容 即添加图片
    Quartz2D-master手动截图
    CoreAnimation-06-CAKeyframeAnimation 相关代码
    CoreAnimation-06-CAKeyframeAnimation
    视频播放
  • 原文地址:https://www.cnblogs.com/skyette/p/6357896.html
Copyright © 2020-2023  润新知