Buy the Ticket

Buy the Ticket
参考:Buy the Ticket

上面博客中好像 n 和 m 的意思写反了,不过问题不大,反着输入就好了,题目中说 n 是 50 的人数,m 是 100 的人数,这里反了一下。另外还需要用到高精度。

公式(m 是 50 的人数,n 是 100 的人数):
\[ (\binom {m+n}{n}-\binom {m+n}{m+1})*m!*n! \]
化简得:
\[ \frac{(m+n)!*(m-n+1)}{m+1} \]
代码:

// Created by CAD on 2019/8/17.
#include <bits/stdc++.h>
using namespace std;
#define MAXN 9999
#define MAXSIZE 10000
#define DLEN 4
class BigNum
{
public:
    int a[MAXSIZE];
    int len;
public:
    BigNum(){len = 1;memset(a,0,sizeof(a));}
    BigNum(const int);
    BigNum &operator=(const BigNum &);
    friend ostream& operator<<(ostream&,  BigNum&);
    BigNum operator*(const BigNum &) const;
    BigNum operator/(const int  &) const;
};
ostream& operator<<(ostream& out,  BigNum& b)
{
    int i;
    cout << b.a[b.len - 1];
    for (i = b.len - 2 ; i >= 0 ; i--)
    {
        cout.width(DLEN);
        cout.fill('0');
        cout << b.a[i];
    }
    return out;
}
BigNum::BigNum(const int b)
{
    int c,d = b;
    len = 0;
    memset(a,0,sizeof(a));
    while (d > MAXN)
    {
        c = d - (d / (MAXN + 1)) * (MAXN + 1);
        d = d / (MAXN + 1);  a[len++] = c;
    }
    a[len++] = d;
}
BigNum & BigNum::operator=(const BigNum & n)
{
    len = n.len;
    memset(a,0,sizeof(a));
    for (int i = 0 ; i < len ; i++)
        a[i] = n.a[i];
    return *this;
}
BigNum BigNum::operator*(const BigNum & T) const
{
    BigNum ret;
    int i,j,up;
    int temp,temp1;
    for (i = 0 ; i < len ; i++)
    {
        up = 0;
        for (j = 0 ; j < T.len ; j++)
        {
            temp = a[i] * T.a[j] + ret.a[i + j] + up;
            if (temp > MAXN)
            {
                temp1 = temp - temp / (MAXN + 1) * (MAXN + 1);
                up = temp / (MAXN + 1);
                ret.a[i + j] = temp1;
            }
            else
            {
                up = 0;
                ret.a[i + j] = temp;
            }
        }
        if (up != 0)
            ret.a[i + j] = up;
    }
    ret.len = i + j;
    while (ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len--;
    return ret;
}
BigNum BigNum::operator/(const int & b) const
{
    BigNum ret;
    int i,down = 0;
    for (i = len - 1 ; i >= 0 ; i--)
    {
        ret.a[i] = (a[i] + down * (MAXN + 1)) / b;
        down = a[i] + down * (MAXN + 1) - ret.a[i] * b;
    }
    ret.len = len;
    while (ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len--;
    return ret;
}
BigNum jc[205];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    jc[0]=jc[1]=BigNum(1);
    for(int i=2;i<=200;++i)
        jc[i]=jc[i-1]*BigNum(i);
    int n=1,m=1,t=0;
    while(cin>>m>>n&&(n+m))
    {
        BigNum ans(1);
        if(m<n) ans=BigNum(0);
        else
            ans=jc[m+n]*BigNum(m+1-n)/(m+1);
        cout<<"Test #"<<++t<<":"<<endl<<ans<<endl;
    }
    return 0;
}
全部评论

相关推荐

行云流水1971:这份实习简历的优化建议: 结构清晰化:拆分 “校园经历”“实习经历” 板块(当前内容混杂),按 “实习→校园→技能” 逻辑排版,求职意向明确为具体岗位(如 “市场 / 运营实习生”)。 经历具象化:现有描述偏流程,需补充 “动作 + 数据”,比如校园活动 “负责宣传” 可加 “运营公众号发布 5 篇推文,阅读量超 2000+,带动 300 + 人参与”;实习内容补充 “协助完成 XX 任务,效率提升 X%”。 岗位匹配度:锚定目标岗位能力,比如申请运营岗,突出 “内容编辑、活动执行” 相关动作;申请市场岗,强化 “资源对接、数据统计” 细节。 信息精简:删减冗余表述(如重复的 “负责”),用短句分点,比如 “策划校园招聘会:联系 10 + 企业,组织 200 + 学生参与,到场率达 85%”。 技能落地:将 “Office、PS” 绑定经历,比如 “用 Excel 整理活动数据,输出 3 份分析表;用 PS 设计 2 张活动海报”,避免技能单独罗列。 优化后需强化 “经历 - 能力 - 岗位需求” 的关联,让实习 / 校园经历的价值更直观。 若需要进一步优化服务,私信
实习,投递多份简历没人回...
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务