zoukankan      html  css  js  c++  java
  • hdu 1133 Buy the Ticket(大数运算)

    ans = (m+n)!*(m-n+1)/(m+1).

    大数乘小数,大数除小数。

    View Code
     1 /*
     2 Author:Zhaofa Fang
     3 Lang:C++
     4 */
     5 #include <cstdio>
     6 #include <cstdlib>
     7 #include <sstream>
     8 #include <iostream>
     9 #include <cmath>
    10 #include <cstring>
    11 #include <algorithm>
    12 #include <string>
    13 #include <utility>
    14 #include <vector>
    15 #include <queue>
    16 #include <stack>
    17 #include <map>
    18 #include <set>
    19 using namespace std;
    20 
    21 typedef long long ll;
    22 #define DEBUG(x) cout<< #x << ':' << x << endl
    23 #define REP(i,n) for(int i=0;i < (n);i++)
    24 #define FOR(i,s,t) for(int i = (s);i <= (t);i++)
    25 #define FORD(i,s,t) for(int i = (s);i >= (t);i--)
    26 #define PII pair<int,int>
    27 #define PB push_back
    28 #define MP make_pair
    29 #define ft first
    30 #define sd second
    31 #define lowbit(x) (x&(-x))
    32 #define INF (1<<30)
    33 
    34 int p[1000],q[1000];
    35 
    36 void print(int a[])
    37 {
    38     int k = 999;
    39     while(k>=0 && !a[k])k--;
    40     FORD(i,k,0)printf("%d",a[i]);
    41     puts("");
    42 }
    43 void pro_Aa(int a[],int b)
    44 {
    45     int c[1000]={0};
    46     int e = 0;
    47     int k = 0;
    48     while(b)
    49     {
    50         for(int j=0;j+k<1000;j++)
    51         {
    52             int tmp = a[j] * (b%10);
    53             int tmp1 = tmp + c[j+k] + e;
    54             c[j+k] = (tmp1)%10;
    55             e = (tmp1)/10;
    56         }
    57         b /= 10;k++;
    58     }
    59     REP(j,1000)a[j]=c[j];
    60 }
    61 void div(int a[],int b)
    62 {
    63     int k = 999;
    64     while(k>=0 && !a[k])k--;
    65     int e = 0;
    66     FORD(i,k,0)
    67     {
    68         int tmp = e*10 + a[i];
    69         a[i] = tmp/b;
    70         e = tmp%b;
    71     }
    72 }
    73 int main()
    74 {
    75     //freopen("in","r",stdin);
    76     //freopen("output.txt","w",stdout);
    77     int m,n;
    78     int cas = 0;
    79     while(~scanf("%d%d",&m,&n))
    80     {
    81         if(!m && !n)break;
    82         printf("Test #%d:\n",++cas);
    83         if(m < n)
    84         {
    85             puts("0");
    86             continue;
    87         }
    88         memset(p,0,sizeof(p));
    89         p[0] = 1;
    90         FORD(i,m+n,2)pro_Aa(p,i);
    91         pro_Aa(p,m-n+1);
    92         div(p,m+1);
    93         print(p);
    94     }
    95     return 0;
    96 }
  • 相关阅读:
    QtDBus编程详解
    QProcess详解
    python 爬虫 亚航 指定日期间的航线
    python 模块
    centos postgres 安装、远程连接
    python 爬虫 anyproxy
    python_scrapy_filespipe重写
    python_xpath
    常见问题汇总
    python_scrapy_log日志
  • 原文地址:https://www.cnblogs.com/fzf123/p/2813389.html
Copyright © 2011-2022 走看看