Spoj 9887 Binomial coefficients 構造,spojbinomial

來源:互聯網
上載者:User

Spoj 9887 Binomial coefficients 構造,spojbinomial

題目連結:點擊開啟連結

#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;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.