zoukankan      html  css  js  c++  java
  • HUST 1698

    http://acm.hust.edu.cn/problem/show/1698

    题目就是要把一个数n分成4段,其中中间两段一定要是奇数。

    问有多少种情况。

    分类,

    奇数 + 奇数 + 奇数 + 奇数

    奇数 + 奇数 + 奇数 + 偶数

    偶数 + 奇数 + 奇数 + 奇数

    偶数 + 奇数 + 奇数 + 偶数

    注意看看能否拆成这样的形式,比如x是奇数的话,最后一种就没可能拆成了。 

    然后奇数表达成 2 * a - 1这个样子,就能列出方程。

    然后就是类似于解a1 + a2 + a3 + a4 = x的问题了。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <bitset>
    LL C(LL n, LL m) {
        if (n < m) return 0; //防止sb地在循环
        if (n == m) return 1;  //C(0,0)也是1的
        LL ans = 1;
        LL mx = max(n - m, m); //这个也是必要的。能约就约最大
        LL mi = n - mx;
        for (int i = 1; i <= mi; ++i) {
            ans = ans * (mx + i) / i;
        }
        return ans;
    }
    
    void work() {
        int n;
        scanf("%d", &n);
        LL ans = 0;
        if ((n + 4) % 2 == 0) ans += C((n + 4) / 2 - 1, 3);
        if ((n + 3) % 2 == 0) ans += C((n + 3) / 2 - 1, 3) * 2;
        if ((n + 2) % 2 == 0) ans += C((n + 2) / 2 - 1, 3);
        static int f = 0;
        printf("Case #%d: %lld
    ", ++f, ans);
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        int t;
        scanf("%d", &t);
        while (t--) work();
        return 0;
    }
    View Code
  • 相关阅读:
    ios 集成react native
    聊聊职场潜规则
    cocopods 问题
    微信小程序实现给循环列表添加点击样式实例
    Android build.gradle
    小程序开发的40个技术窍门,纯干货!
    react-创建组件
    React Native在开发过程中遇到的一些问题(俗称:坑)
    微信小程序 开发过程中遇到的坑(一)
    微信小程序开源项目库汇总
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6357806.html
Copyright © 2011-2022 走看看