HDU 5047 Sawtooth 規律+ C++大數類比 2014 ACM/ICPC Asia Regional Shanghai Online,hdusawtooth

來源:互聯網
上載者:User

HDU 5047 Sawtooth 規律+ C++大數類比 2014 ACM/ICPC Asia Regional Shanghai Online,hdusawtooth

題意:

用x個大M 可以把平面分成至多幾塊。

就是折線切割平面的加強版。

一個簡單的遞推式 : F(x+1) = 16x+1+F(x)

 然後轉成通項公式,然後C++ 位壓大數類比


#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int mod = 100000;struct node {    int v[10];    node() {        memset(v, 0, sizeof v);        v[0] = 1;    }    void out() {        printf("%d", v[v[0]]);        for (int i = v[0] - 1; i >= 1; --i)            printf("%05d", v[i]);        putchar('\n');    }};char ch;void get(ll& x) {    while ((ch = getchar()) < '0' || ch > '9');    x = ch - '0';    while ((ch = getchar()) >= '0' && ch <= '9')        x = x * 10 + ch - '0';}void add(node& i, ll x) {    int mx = 0;    while (x > 0) {        ++ mx;        x = x + i.v[mx];        i.v[mx] = x % mod;        x /= mod;    }    if (mx > i.v[0])        i.v[0] = mx;}void multi(node& a, ll x) {    ll y = 0;    for (int i = 1; i <= a.v[0]; ++i) {        y = a.v[i] * x + y;        a.v[i] = y % mod;        y /= mod;    }    int mx = a.v[0];    while (y > 0) {        ++ mx;        a.v[mx] = y % mod;        y /= mod;    }    a.v[0] = mx;}node Cal(ll n) {    node re;    if (n == 1) {        re.v[1] = 2;    } else {        add(re, n * 8);        multi(re, n - 1);        add(re, n + 1);    }    return re;}int main() {    node one;    one.v[1] = 1;    int T = 0, cas;    ll n;    node ans;        scanf("%d", &cas);    while (cas -- > 0) {        get(n);        ans = Cal(n);        printf("Case #%d: ", ++T);        ans.out();    }    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.