• USACO3.21Factorials


    枚举

     1 #include <iostream>
     2 /*
     3     ID: shangca2
     4     LANG: C++
     5     TASK: fact4
     6  */
     7 #include<cstdio>
     8 #include<cstring>
     9 #include<iostream>
    10 
    11 using namespace std;
    12 int di[5000];
    13 int main()
    14 {
    15     freopen("fact4.in","r",stdin);
    16     freopen("fact4.out","w",stdout);
    17     int i,j,k,n,g=0;
    18     di[0] = 1;
    19     cin>>n;
    20     for(i = 1 ; i <= n ; i++)
    21     {
    22         for(j=0 ; j <= g ; j++)
    23         di[j] *= i;
    24         for(j = 0 ; j <= g ; j++)
    25         {
    26             if(di[j]>9)
    27             {
    28                 di[j+1] += di[j]/10;
    29                 di[j] = di[j]%10;
    30                 if(j+1>g)
    31                 g = j+1;
    32             }
    33         }
    34     }
    35     k=0;
    36     while(di[k]==0&&k<=g)
    37     k++;
    38     cout<<di[k]<<endl;
    39     return 0;
    40 }
    View Code
  • 相关阅读:
    【ccf线上赛普及组 2020】
    【小总结】2020.3.6
    DP优化
    noip2012day2
    noip2012day1
    3.28真题
    数据结构总结
    noi online 普及组
    小总结
    20200229模拟赛
  • 原文地址:https://www.cnblogs.com/shangyu/p/3123136.html
Copyright © 2020-2023  润新知