UVa 10519!! Really Strange!! (recursive)

Source: Internet
Author: User

10519-!! Really Strange!!

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_ problem&problem=1460

Idea: Note the topic "Every two area have exactly two points to intersect and no three circles intersect in a common point", so the nth circle and other N-1 a circle of 2* (n-1) intersection, the newborn into the 2* (n-1) region, so f (n) =f (n-1) +2* (n-1), and then to get f (n) =n^2-n+2, boundary f (0) = 1.

Complete code:

/*0.012s*/#include <bits/stdc++.h> using namespace std;
  
const int MAXN = 210;
  
Char NUMSTR[MAXN];
  
    struct Bign {int len, S[MAXN];
        Bign () {memset (s, 0, sizeof (s));
    len = 1;
    } bign (int num) {*this = num;
    } bign (const char* num) {*this = num;
        } bign operator = (const int num) {char S[MAXN];
        sprintf (S, "%d", num);
        *this = s;
    return *this;
        } bign operator = (const char* num) {len = strlen (num);
        for (int i = 0; i < len; i++) S[i] = num[len-i-1] & 15;
    return *this;
                ///Output Const char* str () const {if (len) {for (int i = 0; i < len; i++)
            Numstr[i] = ' 0 ' + s[len-i-1];
        Numstr[len] = ' the ';
        else strcpy (Numstr, "0");
    return numstr; ///to leading 0 void clean () {while Len > 1 &&!s[len-1]) len--;
        ///plus bign operator + (const bign& b) const {bign C;
        C.len = 0;
            for (int i = 0, g = 0; G | | | i < MAX (Len, B.len); i++) {int x = g;
            if (i < len) x + = S[i];
            if (I < B.len) x + = B.s[i];
            c.s[c.len++] = x% 10;
        g = X/10;
    return C;
        ///minus bign operator-(const bign& B) const {bign C;
        C.len = 0;
            for (int i = 0, g = 0; i < len; i++) {int x = s[i]-G;
            if (I < b.len) x-= B.s[i];
            if (x >= 0) g = 0;
                else {g = 1;
            x + 10;
        } c.s[c.len++] = x;
        } C.clean ();
    return C;
        ///Multiply bign operator * (const bign& b) const {bign C;
        C.len = len + B.len;
for (int i = 0; i < len; i++)            for (int j = 0; J < B.len J + +) C.s[i + j] + = s[i] * B.s[j];
            for (int i = 0; i < c.len-1 i++) {c.s[i + 1] + = c.s[i]/10;
        C.s[i]%= 10;
        } C.clean ();
    return C;
        }///except bign operator/(const bign &b) const {bign ret, cur = 0;
        Ret.len = Len;
            for (int i = len-1 i >= 0; i--) {cur = cur * 10;
            Cur.s[0] = s[i];
                while (cur >= b) {cur = b;
            ret.s[i]++;
        } Ret.clean ();
    return ret;
        }///modulo, remainder bign operator% (const bign &b) Const {bign c = *this/b;
    return *this-c * b;
        BOOL operator < (const bign& b) Const {if (len!= b.len) return Len < B.len; for (int i = len-1 i >= 0; i--) if (S[i]!= b.s[i]) return s[i] < B.S[i];
    return false;
    BOOL operator > (const bign& B) Const {return B < *this; BOOL operator <= (const bign& B) Const {return! (
    b < *this); BOOL operator >= (const bign &b) Const {return! (
    *this < b); BOOL operator = = (CONST bign& b) Const {return! b < *this) &&!
    (*this < b);
    BOOL operator!= (const bign &a) const {return *this > A | | *this < A;
        } bign operator = = (Const bign &a) {*this = *this + A;
    return *this;
        } bign Operator-= (const bign &a) {*this = *this-a;
    return *this;
        } bign operator *= (const bign &a) {*this = *this * A;
    return *this;
        } bign operator/= (const bign &a) {*this = *this/a;
    return *this; } bign operator%= (const bIGN &a) {*this = *this% A;
    return *this;
  
}
};
    int main () {bign n;
        while (gets (NUMSTR)) {n = numstr; Puts (n = 0?)
    "1": (n * n-n + 2). STR ());
return 0; }

Author: csdn Blog Synapse7

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.