zoukankan      html  css  js  c++  java
  • 牛客小白月赛1 I あなたの蛙が帰っています 【卡特兰数】

    题目链接

    https://www.nowcoder.com/acm/contest/85/I

    思路
    A1 不能第一个出栈
    所有的出栈顺序 为第N个卡特兰数
    如果A1第一个出栈 那么所有的出栈顺序就是 第(N - 1)个卡特兰数
    所以 所有可用的出战顺序 就是 H(N) - H (N - 1)
    注意取模

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    
    const double PI  = 3.14159265358979323846264338327;
    const double E   = 2.718281828459;
    const double eps = 1e-6;
    
    const int INF    = 0x3f3f3f3f;
    const int maxn   = 1e5+ 5;
    const ll MOD    = 998244353;
    
    ll ans[maxn] = {1, 1};
    
    ll powerMod(ll x, ll n)
    {
        ll res = 1;
        while (n > 0){
            if  (n & 1) 
                res = (res * x) % MOD;
            x = (x * x) % MOD;
            n >>= 1;   
        }
        return res;
    }
    
    int main()
    {
        for (ll i = 2; i <= maxn; i++)
            ans[i] = ans[i - 1] * (4 * i - 2) % MOD * powerMod(i + 1, MOD - 2)  % MOD;
        int t;
        int count = 1;
        cin >> t;
        while (t--)
        {
            int n;
            scanf("%d", &n);
            printf("Case #%d: %lld
    ", count++, (ans[n]  - ans[n - 1] + 2 * MOD) % MOD);
        }
    }
  • 相关阅读:
    c++ 队列
    17:特殊类成员:函数指针5
    c++ deque 双端队列
    18:字符串-char型字符串
    c++ 16 this 和 继承 及继承机制中的构造函数 与 析构函数
    c++ string char* const char*
    c++ 小片段
    google protobuf 使用示例
    hibernate-cache
    hibernate-criteria查询(二)
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433239.html
Copyright © 2011-2022 走看看