zoukankan      html  css  js  c++  java
  • Lightoj 1090

    题目连接:

      http://www.lightoj.com/volume_showproblem.php?problem=1090

    题目大意:

      给出n,r,p,q四个数字1<=n,r,p,q<=1000000,求出的末尾有几个0?

    解题思路:

      是不是一下子懵了,数字好大,复杂度好高,精度怎么办···············,就问你怕不怕?

      其实都是纸老虎啦,因为10的因子只有2和5,所以可以打表保存从1到当前数字相乘的积中分别含有2,5的个数。然后算出中分别含有2,5的个数,取其最小就是结果。(ps:一定不要因为直接统计10的个数方便,而去统计10的个数,两者还是有不同的)。

     1 #include <cmath>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <iostream>
     6 using namespace std;
     7 //复杂度O(1)
     8 const int maxn = 1000010;
     9 struct node
    10 {
    11     int x, y;
    12 };
    13 node a[maxn];
    14 int main ()
    15 {
    16     int t, n, r, p, q, l = 1;
    17     memset (a, 0, sizeof(a));
    18     int x , y;
    19     x = y = 0;
    20     for (int i=2; i<maxn; i++)
    21     {//打表大法好(^o^)/~
    22         int num = i;
    23         while (num % 2 == 0)
    24         {
    25             x ++;
    26             num /= 2;
    27         }
    28         num = i;
    29         while (num % 5 == 0)
    30         {
    31             y ++;
    32             num /= 5;
    33         }
    34         a[i].x = x;
    35         a[i].y = y;
    36     }
    37     scanf ("%d", &t);
    38     while (t --)
    39     {
    40         scanf ("%d %d %d %d", &n, &r, &p, &q);
    41         int res = min(a[n].x - a[r].x - a[n-r].x + (a[p].x - a[p-1].x) * q, a[n].y - a[r].y - a[n-r].y + (a[p].y - a[p-1].y) * q);
    42         printf ("Case %d: %d
    ", l++, res);
    43     }
    44     return 0;
    45 }
    本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    pandas 数据预处理实例演示
    pandas 包的基本使用
    Numpy 包的基础结构(下)
    Numpy 包的基础结构(上)
    Anaconda的基本使用
    黄金点游戏结果
    个人作业-Week2:案例分析
    结对项目-地铁出行路线规划程序(续)
    关于结对和团队组建
    关于个人博客和Github地址提交
  • 原文地址:https://www.cnblogs.com/alihenaixiao/p/4623179.html
Copyright © 2011-2022 走看看