zoukankan      html  css  js  c++  java
  • TOJ---3654--数学题

    ho-ho- 又连赢 又要打晋级赛了 TM的 白银2 - > 白银1  这是第4次了 .......

    快点写了这题 洗个澡 晚上还要看CR7了

        touch me

    这题的题意 我不用说了吧 太清晰了

    讲下我的做法:

      具备什么样的条件 末尾才会出现0呢  当然是这个数 可以被5整除  广泛点讲 就是这个数的末位上是 0 或 5;

      OK 那其实 知道了这点后  再稍微想想就可以解决了

      题目要让我们求1~2000 个末尾0的时候 最小的n的阶乘  那么我们只要做个预处理 存到一个数组中或map

      我这边用的是 map 感觉 写起来方便点...

      然后 就可以直接o(1)查询了  这边有一点要注意 就是可能题目中让你求末尾8个0  而我们处理之后的结果只有7或9的时候  当然 这是存在的情况

      很简单 我们设末尾0的个数为x 知道mp[x++] !=0 的时候 就求出我们要的答案了

      OK it is over

      贴上 我的代码  ~ 洗澡去了

      

     1 #include <iostream>
     2 #include <map>
     3 using namespace std;
     4 
     5 const int size = 2010;
     6 map<int,int>mp;
     7 int judge(int x)
     8 {
     9     int cnt = 0;
    10     while(x>=5)
    11     {
    12         x/=5;
    13         cnt++;
    14         if( x%5!=0 )
    15             break;
    16     }
    17     return cnt;
    18 }
    19 
    20 void inital()
    21 {
    22     int cnt = 0;
    23     for( int i = 1 ; i<=10000; i++ )
    24     {
    25         if( i%5==0 )
    26         {
    27             cnt+=judge(i);
    28             mp[cnt] = i;
    29         }
    30     }
    31 }
    32 
    33 int main()
    34 {
    35     int n;
    36     inital();
    37     while( ~scanf("%d",&n) )
    38     {
    39         while(n)
    40         {
    41             if(mp[n]!=0)
    42             {
    43                 printf( "%d
    ",mp[n] );
    44                 break;
    45             }
    46             n++;
    47         }
    48     }
    49     return 0;
    50 }
    View Code
    just follow your heart
  • 相关阅读:
    基于C++CJAVA的python入门
    雁栖湖健身计划
    显存的一些知识
    Cuda_bank-conflict
    翻译文章进展
    一些CV界的好资源
    how processor caches work
    LINQ-进阶的扩展方法
    LINQ-基础
    CTFHUB-技能树 基础知识 ctf练习平台
  • 原文地址:https://www.cnblogs.com/radical/p/3791798.html
Copyright © 2011-2022 走看看