首页 > 其他 > 详细

Spoj 9887 Binomial coefficients 构造

时间:2019-05-18 21:37:11      阅读:47      评论:0      收藏:0      [点我收藏+]

标签:include   点击   detail   long long   poj   ()   ems   edi   post   

版权声明:本文为博主原创铁牛棋牌森林舞会,未经博主同意不得转载。 https://blog.csdn.net/qq574857122/article/details/37778285

题目链接:点击打开链接

#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 507;
const long long INF = (long long)1e15;
typedef long long ll;
typedef pair<ll,ll> pii;
ll C[MAX_N][MAX_N];
vector<pii> ord;
ll get(ll nn, int m, ll A) {
    ll ret = 1;
    for (int i = 0; i < m; ++i) {
        if (ret > (A + nn + i - 1) / (nn + i)) return A + 1;
        ret *= (nn + i);
    }
    return ret;
}

void pre(ll n) {
    ll nn = n;
    for (int i = 1; i < 7; ++i) {
            nn *= i;
            ll l = 1, r = INF;
            while (l <= r) {
                ll mid = (l + r) >> 1;
                ll ans = get(mid, i, nn);
                if (ans > nn) r = mid - 1;
                else if (ans < nn) l = mid + 1;
                else {
                    ord.push_back(make_pair(mid + i - 1, i));
                    if (mid - 1 != i)
                        ord.push_back(make_pair(mid + i - 1, mid - 1));
                    break;
                }
            }
    }
}
int main() {
    int T;
    scanf("%d", &T);
    while (T-- > 0) {
        ll n;
        cin >> n;
        ord.clear();
        pre(n);
        C[0][0] = 1;
        for (int i = 1; i < MAX_N; ++i) {
            C[i][0] = C[i][i] = 1;
            for (int j = 1; j < i; ++j) {
                C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
                if (C[i][j] > n) break;
                if (C[i][j] == n) {
                    ord.push_back(make_pair(i, j));
                    if (i - j != j) {
                        ord.push_back(make_pair(i, i - j));
                    }
                }
            }
        }
        sort(ord.begin(), ord.end());
        ord.erase(unique(ord.begin(), ord.end()), ord.end());
        int len = (int)ord.size();
        printf("%d\n", len);
        for (int i = 0; i < len; ++i) {
            if (i == 0) printf("(%lld,%lld)", ord[i].first, ord[i].second);
            else printf(" (%lld,%lld)", ord[i].first, ord[i].second);
        }
        puts("");
    }
    return 0;
}


Spoj 9887 Binomial coefficients 构造

标签:include   点击   detail   long long   poj   ()   ems   edi   post   

原文:https://www.cnblogs.com/mqxnongmin/p/10887071.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
分享档案
最新铁牛棋牌森林舞会
最新免费赚钱棋牌兑换现金
教程昨日排行
© 2014 designnerd.net 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号