zoukankan      html  css  js  c++  java
  • hdu 2519

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2519

    原来可以有递推公式的。。。c[n][m]=c[n-1][m]+c[n-1][m-1];

    orz。。。自己搞了个阶乘。。。orz。。。还用string来处理了。。小题大做了。。。

    View Code
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<string>
     4 #include<vector>
     5 using namespace std;
     6 vector<string>vet;
     7 
     8 string facs(const string &str,int num){
     9     int len=str.size();
    10     int c=0,l=0;
    11     string s="";
    12     for(int i=len-1;i>=0;i--){
    13         c=l+(str[i]-'0')*num;
    14         s+=c%10+'0';
    15         l=c/10;
    16     }
    17     while(l){
    18         s+=l%10+'0';
    19         l/=10;
    20     }
    21     reverse(s.begin(),s.end());
    22     return s;
    23 }
    24 
    25 void Initiate(){
    26     vet.push_back("0");
    27     vet.push_back("1");
    28     vet.push_back("2");
    29     string str="2";
    30     for(int i=3;i<=31;i++){
    31         str=facs(str,i);
    32         vet.push_back(str);
    33     }
    34 }
    35 
    36 string Divide(const string &s1,int n){
    37     string s="";
    38     int len=s1.size();
    39     int c=0,l=0;
    40     for(int i=0;i<len;i++){
    41         c=l*10+s1[i]-'0';
    42         l=c%n;
    43         c=c/n;
    44         if(c==0&&s.size()==0)continue;
    45         else s+=c+'0';
    46     }
    47     return s;
    48 }
    49 
    50 
    51 
    52 int main(){
    53     Initiate();
    54     int _case;
    55     scanf("%d",&_case);
    56     while(_case--){
    57         int n,m;
    58         scanf("%d%d",&n,&m);
    59         if(n==m){
    60             printf("1\n");
    61         }else if(n<m){
    62             printf("0\n");
    63         }else {
    64             string s1=vet[n];
    65             for(int i=2;i<=m;i++){
    66                 s1=Divide(s1,i);
    67             }
    68             for(int i=2;i<=(n-m);i++){
    69                 s1=Divide(s1,i);
    70             }
    71             cout<<s1<<endl;
    72         }
    73     }
    74     return 0;
    75 }
  • 相关阅读:
    18周个人总结
    十六周个人总结
    排球积分规则程序
    十四周软件工程总结
    本周总结
    排球积分规则
    我的计算机生涯
    排球比赛记分员
    《怎样成为一个高手》观后感
    冲刺作业
  • 原文地址:https://www.cnblogs.com/wally/p/2976481.html
Copyright © 2011-2022 走看看