The strongest de combat effectiveness "large number"

Source: Internet
Author: User

Strongest de combat time limit: 1 Sec Memory Limit: MB
Submit: Solved: 13
[Submit] [Status] [Web Board] Description

During the spring and Autumn period, Zhao is vast and abundant, and the people live happily. But many countries are eyeing it, ready to unite to launch a war against Zhao.

Obviously, in the face of a number of national forces to combat, Zhao's strength is clearly at a disadvantage. Combat effectiveness is a key factor in determining the success or failure of a war, in general, the combat effectiveness of a force is proportional to the troop's strength. But when a troop is divided into several combat teams, the combat effectiveness of the Force will be greatly enhanced.

The combat effectiveness of a force can be calculated by the following two rules:

1. If the strength of a combat team is n, then the combat team will have a fighting force of N;

2. If a unit is divided into several combat teams, the total combat effectiveness of the Force is the product of the combat effectiveness of these teams.

For example: The strength of a force of 5 when the effectiveness analysis is as follows:

Case

Operational arrangements

Total combat effectiveness.

1

1,1,1,1,1 (divided into 5 combat teams)

1*1*1*1*1=1

2

1,1,1,2 (divided into 4 combat teams)

1*1*1*2=2

3

1,2,2 (divided into 3 combat teams)

1*2*2=4

4

1,1,3 (divided into 3 combat teams)

1*1*3=3

5

2,3 (divided into 2 combat teams)

2*3=6

6

1,4 (divided into 2 combat teams)

1*4=4

7

5 (divided into 1 combat teams)

5=5

Obviously, the troops are divided into 2 combat teams (one is 2, the other is 3), the total combat effectiveness reached the maximum!

Input

The first line: n indicates that there are n sets of test data. (2<=n<=5)

Next there are n lines, each line has an integer ti represents the strength of the Zhao Army. (1 <= Ti <=) I=1, ... N

Output

For each row of test data, the output occupies one row, and only an integer s, representing the maximum combat effectiveness of the battle arrangement.

Sample Input
254
Sample Output
64
HINT

#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include < math.h> #include <ctype.h> #include <time.h> #include <queue> #include <iterator>using  namespace std; #define MAXN 9999#define MAXSIZE 1010#define dlen 4class bignum{private:int a[1000];  Can control the number of digits of the number of int len;public:bignum () {len = 1; memset (A, 0, sizeof (a));}     constructor Bignum (const int);   Converts a variable of type int to a large number bignum (const char*); Converts a variable of a string type to a large number bignum (const bignum &); Copy constructor Bignum &operator= (const bignum &); Overloaded assignment operators, assigning values between large numbers friend istream& operator>> (istream&, bignum&); Overloaded input operator friend ostream& operator<< (ostream&, bignum&);  Overloaded output operator Bignum operator+ (const bignum &) const;  Overloaded addition operator, the addition of two large numbers bignum operator-(const bignum &) const;  The overloaded subtraction operator, the subtraction operation between two large numbers bignum operator* (const bignum &) const;     Overloaded multiplication operator, the multiplication operation between two large numbers bignum operator/(const int &) const; Overloaded division operator, large number divides an integer bignumoperator^ (const int &) const;        Large number of n-th-square operations int operator% (const int &) const;   Large number of variables of an int type modulo operation bool Operator> (const bignum &t) const;      The large number and the size of another large number compare bool operator> (const int &t) const;        The size of a variable of large number and an int type is compared with void print (); Output large number};  Bignum::bignum (const int B)//Converts a variable of type int to a large number {int c, d = B;len = 0;memset (A, 0, sizeof (a)), while (D&GT;MAXN) {c = d-(d /(MAXN + 1)) * (MAXN + 1);d = d/(MAXN + 1); a[len++] = c;} a[len++] = D;} Bignum::bignum (const char *s)//Converts a variable of a string type to a large number {int T, K, index, L, I;memset (A, 0, sizeof (a)); L = strlen (s); len = l/dlen;if (l%dlen) Len++;index = 0;for (i = L-1; I >= 0; I-= Dlen) {t = 0;k = I-dlen + 1;if (k <0) k = 0;for (int j = k; J <= I; j + +) T = T * + s[j]-' 0 '; a[index++] = t;}} Bignum::bignum (const bignum &t): Len (T.len)//copy constructor {int I;memset (a, 0, sizeof (a)); for (i = 0; i<len; i++) a[i] = T . A[i];} Bignum & bignum::operator= (const bignum &n)//overloaded assignment operator, large number assignment operation {int i;len = N.len;memset (A, 0, sIzeof (a)); for (i = 0; i<len; i++) a[i] = N.a[i];return *this;} istream& operator>> (IStream &in, Bignum &b) {char ch[maxsize * 4];int i = -1;in >> ch;int L = Strle n (ch); int count = 0, sum = 0;for (i = L-1; I >= 0;) {sum = 0;int t = 1;for (int j = 0; j<4 && i >= 0; j+ +, I--, t *=) {sum + = (ch[i]-' 0 ') *t;} B.a[count] = sum;count++;} B.len = Count++;return in;} ostream& operator<< (ostream& out, bignum& B)//overloaded output operator {int i;cout << b.a[b.len-1];for (i = B.le N-2; I >= 0; i--) {printf ("%04d", B.a[i]);} return out;} Bignum bignum::operator+ (const bignum &t) const//Two large number of addition operations {Bignum T (*this); int i, big;big = T.len>len? T.len:len;for (i = 0; i<big; i++) {T.a[i] + = t.a[i];if (T.A[I]&GT;MAXN) {t.a[i + 1]++;t.a[i]-= MAXN + 1;}} if (T.a[big]! = 0) T.len = big + 1;else T.len = Big;return t;} Bignum bignum::operator-(const bignum &t) const//Two large number subtraction operation {int I, J, Big;bool Flag; Bignum T1, t2;if (*this>t) {t1 = *this;T2 = T;flag = 0;} ELSE{T1 = T;t2 = *this;flag = 1;} Big = t1.len;for (i = 0; i<big; i++) {if (T1.a[i]<t2.a[i]) {j = i + 1;while (t1.a[j] = = 0) j++;t1.a[j--]--;while (j> i) t1.a[j--] + = Maxn;t1.a[i] + + MAXN + 1-t2.a[i];} else T1.a[i]-= T2.a[i];} T1.len = Big;while (t1.a[t1.len-1] = = 0 && t1.len>1) {t1.len--;big--;} if (flag) t1.a[big-1] = 0-t1.a[big-1];return T1;} Bignum bignum::operator* (const bignum &t) const//Two large number multiplied by {bignum Ret;int I, J, Up;int Temp, temp1;for (i = 0; i<l En i++) {up = 0;for (j = 0; j<t.len; j + +) {temp = a[i] * T.a[j] + ret.a[i + j] + up;if (TEMP&GT;MAXN) {Temp1 = temp-temp/ (MAXN + 1) * (MAXN + 1); up = temp/(MAXN + 1); Ret.a[i + j] = Temp1;} Else{up = 0;ret.a[i + j] = temp;}} if (up! = 0) Ret.a[i + j] = up;} Ret.len = i + j;while (ret.a[ret.len-1] = = 0 && ret.len>1) ret.len--;return ret;} Bignum bignum::operator/(const int &b) const//large number divides an integer {bignum ret;int i, down = 0;for (i = len-1; I >= 0; i --) {Ret.a[i] = (A[i]+ down* (MAXN + 1))/B;down = A[i] + down* (MAXN + 1)-ret.a[i] * b;} Ret.len = Len;while (ret.a[ret.len-1] = = 0 && ret.len>1) ret.len--;return ret;} int bignum::operator% (const int &b) const//large number modulo a variable of type int {int I, d = 0;for (i = len-1; I >= 0; i--) d = ((d* (MAXN + 1)) % B + a[i])% B;return D;} Bignum bignum::operator^ (const int &n) const//large number of n-th square operations {Bignum T, ret (1), int i;if (n<0) exit ( -1), if (n = = 0) return 1 if (n = = 1) return *this;int m = N;while (m>1) {t = *this;for (i = 1; (I << 1) <= m; I <<= 1) t = t*t;m-= I;ret = ret*t;if (M = = 1) ret = ret* (*this);} return ret;}  BOOL Bignum::operator> (const bignum &t) const//large number and another large number size comparison {int ln;if (Len>t.len) return true;else if (len = = T.len) {ln = Len-1;while (A[ln] = t.a[ln] && ln >= 0) ln--;if (ln >= 0 && A[ln]>t.a[ln]) return True;elsereturn false;} Elsereturn false;} BOOL Bignum::operator> (const int &t) const//large number and an int type variable size comparison {Bignum B (t); return *thiS>b;} void Bignum::p rint ()//output large number {int i;printf ("%d", a[len-1]), for (i = len-2; I >= 0; i--) printf ("%04d", A[i]);p rintf ( "\ n");} int a[3010]; Bignum P[3010];int Main (void) {int I, n;cin >> n;while (n--) {cin >> i;if (i = = 1) cout << "1" << end L;else{bignum bign (1); while (i) {if (i = = 1) {bign = (BIGN/3) * 4;i-= 1;} else if (i = = 2) {bign = Bign * 2;i-= 2;} Else{bign = bign * 3;i-= 3;}} Bign.print ();}} return 0;}



The strongest de combat effectiveness "large number"

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.