HDU 5047 Sawtooth Law + C + + large number simulation ACM/ICPC Asia regional Shanghai Online

Source: Internet
Author: User
Tags cas

Test instructions

Use x large m to divide a plane into several blocks.

is the enhanced version of the polyline cut plane.

A simple recursive formula: F (x+1) = 16x+1+f (x)

Then turn it into a pass-through formula, and then C + + bit-press the large number simulation


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


HDU 5047 Sawtooth Law + C + + large number simulation ACM/ICPC Asia regional Shanghai Online

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.