NYOJ-541-the strongest de combat effectiveness (fifth session of the Henan Province Program design Contest-Large number!!) )

Source: Internet
Author: User

Strongest de combat time limit: +Ms | Memory Limit:65535KB Difficulty:3
Describe

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<=1000) 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
2
5
4
Sample output
6
4
Source
fifth session of Henan Province Program design Competition


AC Code:

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int ans[205];int Multiply (int x) {    for (Int. up=0, i=0; i<200; i++) {up        = ans[i] * x + up;        Ans[i] = up%;        Up/=;}    } int main () {    int N;    scanf ("%d", &n);    while (n--) {        memset (ans, 0, sizeof (ans)); ans[0]=1;        int A;        scanf ("%d", &a);        int n = A/3, I;        if (a%3 = = 1) n--;        for (i=0; i<n; i++)        multiply (3);        if (a%3 = = 1) multiply (4);        else if (a%3==2) multiply (2);        for (i=200;i>=0;i--)            if (ans[i]) break;        for (; i>0; i--)            printf ("%d", ans[i]);        printf ("%d\n", Ans[0]);    }    return 0;}



NYOJ-541-the strongest de combat effectiveness (fifth session of the Henan Province Program design Contest-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.