zoukankan      html  css  js  c++  java
  • 2017ACM暑期多校联合训练

    题目链接

    Problem Description
    There is a youngster known for amateur propositions concerning several mathematical hard problems.

    Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between 0 and (2m−1) (inclusive).

    As a young man born with ten fingers, he loves the powers of 10 so much, which results in his eccentricity that he always ranges integers he would like to use from 1 to 10k (inclusive).

    For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.

    Given the positive integer m, your task is to determine maximum possible integer k that is suitable for the specific supercomputer.

    Input
    The input contains multiple test cases. Each test case in one line contains only one positive integer m, satisfying 1≤m≤105.

    Output
    For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.

    Sample Input
    1
    64

    Sample Output
    Case #1: 0
    Case #2: 19

    分析:
    其实就是一个公式对应的求解过程,在m已知的情况下求k,其关系式为:
    10^k=2^m-1

    看到这个式子首先想到用对数公式来化简,但是因为等式右面的式子是2^m-1这样的话是没有办法化简得,有没有办法解决呢?
    我们注意到一点就是不管2的几次幂,其最后的一位数字都是在2,4,6,8这几个数字中循环,所以尽管将其结果后面减去的哪个1不考虑也不会影响其十位数的大小,这样的话转换成10的幂次也不会改变。

    关系式就变成10^k=2^m两边同时取以10为底的对数然后将k表示出来就是:k=m*log10(2);

    #include<iostream>
    #include <cmath>
    #include <stdio.h>
    using namespace std;
    int main()
    {
       int m,Case=0;
       while(~scanf("%d",&m))
       {
           Case++;
            int k=(int)(m*log10(2));
            printf("Case #%d: %d
    ", Case, k);
       }
        return 0;
    }
    
  • 相关阅读:
    设置 tableview 的背景颜色,总是有蒙层
    设置 tableview 的背景颜色,总是不生效
    bug: 在使用HMSegmentedControl时,设置selectionIndicatorEdgeInsets对左右边界没有用
    心情烦闷annoying,贴几个图!唉!annoying
    [EffectiveC++]item28:避免返回handles指向对象内部成分
    Memorize and recite an important historical speech
    NCE3
    NCE2
    015 volatile关键字 线程函数的lParam 原子操作和旋转锁.
    015 原子操作 旋转锁
  • 原文地址:https://www.cnblogs.com/cmmdc/p/7238456.html
Copyright © 2011-2022 走看看