• 【CodeVS】 p1696 奇怪的函数


    题目描述 Description

        自从得到上次的教训后,John的上课态度认真多了,也变得更爱动脑筋了。今天他又学习了一个新的知识:关于 xk 的位数。

        如果x大于0小于l,那么位数=1+小数部分×k,

        如果x≥l,那么位数=trunc(ln(x)/ln(10)×k)+1+小数部分×k。

        根据这些函数知识,他学会了求xk的位数了。但他又想到了另外一个问题,如果已知位数N,能不能求出使得 xk 达到或超过N位数字的最小正整数x是多少?

    输入描述 Input Description

        输入一个正整数n(n≤2000000000)。

    输出描述 Output Description

        输出使得 xk 达到n位数字的最小正整数x。

    样例输入 Sample Input

        11

    样例输出 Sample Output

        10

    思路分析:

    换底公式:

    log(a)(b)=log(c)(b)/log(c)(a)(a,c均大于零且不等于1)

    求位数:

    位数

    =log(x^x)/ln(10)+1 

    =x*(log(x)/log(10))

    基本二分

    Source :

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #define n 2000000000
     5 using namespace std;
     6 int main()
     7 {
     8     long long m,l,r;
     9     long long a,w;
    10     scanf("%lld",&a);
    11     l=1;
    12     r=a*3;
    13     while (l<r)
    14     {
    15         //l=1;
    16     //    r=n*3;
    17         m=(l+r)/2;
    18         w=trunc(log(m)/log(10)*m)+1;
    19         if (w<a)
    20             l=m+1;
    21         else
    22             r=m;
    23     }
    24     printf("%lld",l);
    25     return 0;
    26 }

     

     

    —Anime Otaku Save The World.
  • 相关阅读:
    一点优化小知识
    网站结构优化之一
    [JOISC 2016 Day 3] 电报
    [HDU 6157] The Karting
    [JOISC 2015 Day2] Keys
    Educational Codeforces Round 107 (Rated for Div. 2)
    [JOISC 2020 Day4] 治疗计划
    CF1131G Most Dangerous Shark
    [APIO2016] 划艇
    [ICPC World Finals 2018] 绿宝石之岛
  • 原文地址:https://www.cnblogs.com/DMoon/p/4912457.html
Copyright © 2020-2023  润新知