Little boxes on the hillside.
Little boxes made of ticky-tacky.
Little boxes.
Little boxes.
Little boxes all the same.
There is a green boxes, and B pink boxes.
and C blue boxes and D yellow boxes.
And they is all made out of ticky-tacky.
And they all look just the same.
Inputthe input has several test cases. The first line contains the integer t (1≤t≤10) which was the total number of test cases.
For each test case, a line contains four non-negative integers a, B, C and D where a, B, C, d≤2^62, indicating the Numbe RS of green boxes, pink boxes, blue boxes and yellow boxes.
Outputfor each test case, output a line with the total number of boxes.
Sample Input
41 2 3 40 0 0 01 0 0 0111 222 333 404
Sample Output
10011070
Puzzle: Test instructions is the result of seeking A+b+c+d
C + + large number template can be Orz
#include <bits/stdc++.h>using namespace std;//base and base_digits must be consistentconstexpr int base = 100000000 0;constexpr int base_digits = 9;struct bigint{vector<int> z; int sign; bigint (): sign (1) {} bigint (Long Long v) {*this = V;} bigint& operator= (Long long v) {sign = v < 0? -1:1; V*=sign; Z.clear (); for (; v > 0; v = v/base) z.push_back ((int) (v base)); return *this; } bigint (const string& s) {read (s);} bigint& operator+= (const bigint& Other) {if (sign = = Other.sign) {for (int i = 0, CA Rry = 0; I < Other.z.size () | | Carry ++i) {if (I==z.size ()) z.push_back (0); Z[i] + = carry + (I < other.z.size () Other.z[i]: 0); carry = Z[i] >= base; if (carry) z[i]-= base; }} else if (other! = 0/* Prevent infinite loop */) {*thIS-=-other; } return *this; } friend bigint operator+ (bigint A, const bigint& b) {return a + = B; } bigint& operator-= (const bigint& Other) {if (sign = = Other.sign) {if (sign = = 1 && *this >= Other | | Sign = =-1 && *this <= Other) {for (int i = 0, carry = 0; I < other.z.size () | | c Arry; ++i) {Z[i]-= carry + (I < other.z.size ()? Other.z[i]: 0); carry = Z[i] < 0; if (carry) z[i] + = base; } trim (); } else {*this = other-*this; This->sign =-this->sign; }} else *this + =-other; return *this; } friend bigint operator-(bigint a,const bigint& b) {return A-= B; } bigint& operator*= (int v) {if (v<0) sign=-sIgn,v=-v; for (int i=0,carry=0;i<z.size () | | carry;++i) {if (I==z.size ()) z.push_back (0); Long Long cur = (long long) z[i] * v + carry; carry = (int) (cur/base); Z[i] = (int) (cur% base); } trim (); return *this; } bigint operator* (int v) const {return bigint (*this) *= v; } friend Pair<bigint, bigint> divmod (const bigint& A1, Const bigint& B1) {int norm = base/(b 1.z.back () + 1); bigint a = a1.abs () * norm; bigint b = b1.abs () * norm; bigint Q, R; Q.z.resize (A.z.size ()); for (int i = (int) a.z.size ()-1; I >= 0; i--) {r*=base; r+=a.z[i]; int S1 = b.z.size () < R.z.size ()? R.z[b.z.size ()]: 0; int s2 = b.z.size ()-1 < R.z.size ()? R.z[b.z.size ()-1]: 0; int d = (int) ((Long Long) s1 * base + s2)/b.z.back ()); R-= b * D; while (R < 0) r+=b,--D; Q.z[i] = D; } q.sign = A1.sign * b1.sign; R.sign = a1.sign; Q.trim (); R.trim (); return {q, r/norm}; } friend bigint sqrt (const bigint& A1) {bigint a=a1; while (A.z.empty () | | A.z.size ()%2==1) a.z.push_back (0); int n = a.z.size (); int firstdigit = (int):: sqrt ((double) a.z[n-1] * base + a.z[n-2]); int norm = base/(firstdigit + 1); a *= norm; a *= norm; while (A.z.empty () | | A.z.size ()%2==1) a.z.push_back (0); bigint r = (long Long) a.z[n-1] * base + a.z[n-2]; Firstdigit = (int):: sqrt ((double) a.z[n-1] * base + a.z[n-2]); int q = firstdigit; bigint Res; for (int j = N/2-1, J >= 0; j--) {for (;; --Q) {bigint r1= (R (res*2*base+q) *q) *base*base+ (j>0? ( Long long) a.z[2*j-1]*base+a.z[2*j-2]:0); if (r1>=0) {r=r1; break;} } res*=base;res+=q; if (j>0) {int d1 = res.z.size () + 2 < R.z.size ()? R.z[res.z.size () + 2]: 0; int d2 = Res.z.size () + 1 < r.z.size ()? R.z[res.z.size () + 1]: 0; int d3 = Res.z.size () < R.z.size ()? R.z[res.z.size ()]:0; Q = (int) ((Long Long) d1*base*base+ (long Long) d2*base+d3)/(firstdigit*2)); }} Res.trim (); return res/norm; } bigint operator/(const bigint& v) Const {return divmod (*this, v). First; } bigint operator% (const bigint& v) Const {return divmod (*this, v). Second; } bigint& operator/= (int v) {if (v<0) sign=-sign,v=-v; for (int i = (int) z.size ()-1, rem = 0; I >= 0; i.) {long long cur = z[i] + rem * (long long) base; Z[i] = (int) (cur/v); rem = (int) (cur% v); } trim (); return *this; } bigint operator/(int v) const { return bigint (*this)/= v; } int operator% (int v) const {if (v<0) v=-v; int m=0; for (int i= (int) z.size () -1;i>=0;--i) m= (int) ((z[i]+m* (long Long) base)%v); return m * SIGN; } bigint& operator*= (const bigint& v) {*this = *this * v; return *this; } bigint& operator/= (const bigint& v) {*this = *this/v; return *this; } bool operator< (const bigint& v) Const {if (sign!=v.sign) return sign < v.sign; if (Z.size ()!=v.z.size ()) return z.size () *sign<v.z.size () *v.sign; for (int i = (int) z.size ()-1; I >= 0; i--) if (z[i]! = V.z[i]) return z[i] * Sign < v.z[i] * sign; return false; } bool Operator> (const bigint& v) Const {return v < *this;} BOOL Operator<= (const bigint& v) Const {return! ( v < *this); } bool operator>= (const bigint& v) Const {return! ( *this < V); } bool Operator== (const bigint& v) Const {return! *this < v) &&! (v < *this); } bool operator!= (const bigint& v) Const {return *this < V | | v < *this;} void Trim () {while (!z.empty () && z.back () = = 0) z.pop_back (); if (Z.empty ()) sign = 1; } bool Iszero () const {return z.empty ();} Friend BigInt operator-(bigint v) {if (!v.z.empty ()) v.sign =-v.sign; return v; } bigint ABS () const {return sign = = 1? *this:-*this; A long long longvalue () const {Long Long res = 0; for (int i = (int) z.size ()-1; I >= 0; i--) res = res * base + z[i]; return res * SIGN; } friend bigint gcd (const bigint& A, const bigint& b) {return B.iszero ()? A:GCD (b, a% B); } friend bigint LCM (const bigint& A, const bigint& b) {return A/GCD (A, b) * b; } void Read (const string& s) {sign = 1; Z.clear (); Int pos = 0; while (Pos < S.size () && (s[pos] = = '-' | | s[pos] = = ' + ')} {if (s[pos] = = '-') sign =-sign; ++pos; } for (int i= (int) s.size () -1;i>=pos;i-=base_digits) {int x=0; for (int j=max (pos,i-base_digits+1); j<=i;j++) x=x*10+s[j]-' 0 '; Z.push_back (x); } trim (); } friend istream& operator>> (istream& stream, bigint& v) {string S; Stream >> S; V.read (s); return stream; } friend ostream& operator<< (ostream& stream, const bigint& v) {if (v.sign = =-1) stream &L t;< '-'; Stream << (V.z.empty () 0:v.z.back ()); for (int i = (int) v.z.size ()-2; I >= 0; i) stream << setw (base_digits) << Setfill (' 0 ') <&L T V.z[i]; return stream; } Static vector<int> Convert_base (const vector<int>& A, int old_digits, int new_digits) {Vector<long long> p (Max (old_digits, new_digits) + 1); P[0] = 1; for (int i=1;i<p.size (); i++) p[i]=p[i-1]*10; vector<int> Res; Long long cur = 0; int cur_digits = 0; for (int v:a) {cur + = v * P[cur_digits]; Cur_digits + = Old_digits; while (cur_digits >= new_digits) {res.push_back (int (cur% p[new_digits])); Cur/= p[new_digits]; Cur_digits-= new_digits; }} res.push_back ((int) cur); while (!res.empty () && res.back () ==0) res.pop_back (); return res; } typedef vector<long Long> VLL; Static VLL karatsubamultiply (const vll& A, const vll& b) {int n=a.size (); Vll Res (n + N); if (n <=) {for (int i = 0, i < n; i++) for (int j = 0; J < N; j + +) Res[i +J] + = a[i] * B[j]; return res; } int k = n >> 1; VLL A1 (A.begin (), A.begin () + K); VLL A2 (A.begin () + K, a.end ()); VLL B1 (B.begin (), B.begin () + K); Vll B2 (B.begin () + K, b.end ()); Vll a1b1 = karatsubamultiply (A1, B1); Vll a2b2 = karatsubamultiply (A2, B2); for (int i=0;i<k;i++) a2[i]+=a1[i]; for (int i=0;i<k;i++) b2[i]+=b1[i]; Vll r = karatsubamultiply (A2, B2); for (int i=0;i<a1b1.size (); i++) r[i]-=a1b1[i]; for (int i=0;i<a2b2.size (); i++) r[i]-=a2b2[i]; for (int i=0;i<r.size (); i++) res[i+k]+=r[i]; for (int i=0;i<a1b1.size (); i++) res[i]+=a1b1[i]; for (int i = 0;i<a2b2.size (); i++) res[i+n]+=a2b2[i]; return res; } bigint operator* (const bigint& v) const {vector<int> a6=convert_base (this->z,base_digits,6); Vector<int> b6=convert_base (v.z,base_digits,6); Vll A (A6.begin (), A6.end ()); Vll b(B6.begin (), B6.end ()); while (A.size () <b.size ()) a.push_back (0); while (B.size () <a.size ()) b.push_back (0); while (A.size () & (A.size ()-1)) A.push_back (0), b.push_back (0); Vll C=karatsubamultiply (A, b); bigint Res; Res.sign = sign * v.sign; for (int i = 0, carry = 0; I < c.size (); i++) {long Long cur = c[i] + carry; Res.z.push_back ((int) (cur% 1000000)); carry = (int) (cur/1000000); } res.z = Convert_base (res.z, 6, base_digits); Res.trim (); return res; }};int Main () {ios::sync_with_stdio (0); Cin.tie (0); BigInt A, B, C, D; int T; Cin >> T; while (t--) {cin >>a>>b>>c>>d; A=a+b+c+d; cout<<a<<endl; } return 0;}
ACM/ICPC Shenyang I question Little Boxes