hdu 1023 Train Problem II

本文介绍了一种使用自定义大数类实现卡特兰数的计算方法。通过递推公式 f(n)=f(n-1)*(n*4-2)/(n-1),解决了HDU ACM 1023题目中对卡特兰数的高效求解问题。

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023
卡特兰数。。
f(n)=f(n1)(n42)/(n1)

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cstdio>
#include<vector>
#include<string>
#include<map>
#include<set>
using std::cin;
using std::max;
using std::cout;
using std::endl;
using std::string;
using std::istream;
using std::ostream;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, j, n) for (int i = j; i < (int)(n); i++)
#define fork(i, k, n) for (int i = (int)k; i <= (int)n; i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
struct BigN {
    typedef unsigned long long ull;
    static const int Max_N = 2010;
    int len, data[Max_N];
    BigN() { memset(data, 0, sizeof(data)), len = 0; }
    BigN(const int num) {
        memset(data, 0, sizeof(data));
        *this = num;
    }
    BigN(const char *num) {
        memset(data, 0, sizeof(data));
        *this = num;
    }
    void clear() { len = 0, memset(data, 0, sizeof(data)); }
    BigN& clean(){ while (len > 1 && !data[len - 1]) len--;  return *this; }
    string str() const {
        string res = "";
        for (int i = len - 1; ~i; i--) res += (char)(data[i] + '0');
        if (res == "") res = "0";
        res.reserve();
        return res;
    }
    BigN operator = (const int num) {
        int j = 0, i = num;
        do data[j++] = i % 10; while (i /= 10);
        len = j;
        return *this;
    }
    BigN operator = (const char *num) {
        len = strlen(num);
        for (int i = 0; i < len; i++) data[i] = num[len - i - 1] - '0';
        return *this;
    }
    BigN operator + (const BigN &x) const {
        BigN res;
        int n = max(len, x.len) + 1;
        for (int i = 0, g = 0; i < n; i++) {
            int c = data[i] + x.data[i] + g;
            res.data[res.len++] = c % 10;
            g = c / 10;
        }
        return res.clean();
    }
    BigN operator * (const BigN &x) const {
        BigN res;
        int n = x.len;
        res.len = n + len;
        for (int i = 0; i < len; i++) {
            for (int j = 0, g = 0; j < n; j++) {
                res.data[i + j] += data[i] * x.data[j];
            }
        }
        for (int i = 0; i < res.len - 1; i++) {
            res.data[i + 1] += res.data[i] / 10;
            res.data[i] %= 10;
        }
        return res.clean();
    }
    BigN operator * (const int num) const {
        BigN res;
        res.len = len + 1;
        for (int i = 0, g = 0; i < len; i++) res.data[i] *= num;
        for (int i = 0; i < res.len - 1; i++) {
            res.data[i + 1] += res.data[i] / 10;
            res.data[i] %= 10;
        }
        return res.clean();
    }
    BigN operator - (const BigN &x) const {
        assert(x <= *this);
        BigN res;
        for (int i = 0, g = 0; i < len; i++) {
            int c = data[i] - g;
            if (i < x.len) c -= x.data[i];
            if (c >= 0) g = 0;
            else g = 1, c += 10;
            res.data[res.len++] = c;
        }
        return res.clean();
    }
    BigN operator / (const BigN &x) const {
        BigN res, f = 0;
        for (int i = len - 1; ~i; i--) {
            f *= 10;
            f.data[0] = data[i];
            while (f >= x) {
                f -= x;
                res.data[i]++;
            }
        }
        res.len = len;
        return res.clean();
    }
    BigN operator % (const BigN &x) {
        BigN res = *this / x;
        res = *this - res * x;
        return res;
    }
    BigN operator += (const BigN &x) { return *this = *this + x; }
    BigN operator *= (const BigN &x) { return *this = *this * x; }
    BigN operator -= (const BigN &x) { return *this = *this - x; }
    BigN operator /= (const BigN &x) { return *this = *this / x; }
    BigN operator %= (const BigN &x) { return *this = *this % x; }
    bool operator <  (const BigN &x) const {
        if (len != x.len) return len < x.len;
        for (int i = len - 1; ~i; i--) {
            if (data[i] != x.data[i]) return data[i] < x.data[i];
        }
        return false;
    }
    bool operator >(const BigN &x) const { return x < *this; }
    bool operator<=(const BigN &x) const { return !(x < *this); }
    bool operator>=(const BigN &x) const { return !(*this < x); }
    bool operator!=(const BigN &x) const { return x < *this || *this < x; }
    bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
    friend istream& operator >> (istream &in, BigN &x) {
        string src;
        in >> src;
        x = src.c_str();
        return in;
    }
    friend ostream& operator << (ostream &out, const BigN &x) {
        out << x.str();
        return out;
    }
}A[101], B;
inline void init() {
    A[1] = 1;
    rep(i, 2, 101) {
        B = 4 * i - 2;
        A[i] = A[i - 1] * B / (i + 1);
        B.clear();
    }
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w+", stdout);
#endif
    init();
    std::ios::sync_with_stdio(false);
    int n;
    while (cin >> n) cout << A[n] << endl;
    return 0;
}
html,css,js,javascript,按钮 # 灵动波纹按钮:打造富有生命力的交互视觉盛宴 在网页设计中,按钮作为用户交互的核心元素,其视觉表现力直接影响用户体验。这款“灵动波纹按钮”以独特的动态效果打破传统静态设计的局限,通过CSS动画赋予界面鲜活的生命力。按钮采用柔和的青绿色背景(#00b894)与纯白色文字形成鲜明对比,圆角切割的边缘(20px圆角设计)增添了亲和力,而左下角的直角处理则巧妙平衡了圆润感,塑造出既友好又不失个性的视觉形象。 其核心亮点在于悬停时触发的波浪动画——通过伪元素构建的半透明白色矩形,以45度角为轴进行周期性位移,模拟水波流动的韵律。动画采用1秒为周期的ease-in-out曲线,使波纹运动既有加速的张力又有减速的缓冲,呈现出自然流畅的视觉节奏。这种设计不仅增强了交互反馈的直观性,更通过动态元素吸引用户注意力,引导操作行为。 技术实现上,通过Tailwind CSS实现基础样式布局,结合CSS伪元素与关键帧动画构建动态效果:利用overflow:hidden隐藏超出按钮范围的动画元素,通过transform属性的translate与rotate组合实现斜向位移,rgba颜色模式确保波纹的透明层次感。整体代码结构简洁清晰,将样式与逻辑分离,既保证了视觉效果的精致度,又兼顾了开发维护的便捷性。 此设计适用于各类需要强调交互的场景,无论是表单提交、功能触发还是页面跳转,都能通过这一灵动的波纹效果提升用户操作的愉悦感,让简单的按钮成为界面设计中的点睛之笔,在细节处彰显设计的温度与巧思。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值