ural 1222. Chernobyl’ Eagles
1222. Chernobyl’ Eagles
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
A Chernobyl’ eagle has several heads (for example, the eagle on the Russian National Emblem is a very typical one, having two heads; there exist Chernobyl’ eagles having twenty-six, one and even zero heads). As all eagles, Chernobyl’ eagles are very intelligent. Moreover, IQ of a Chernobyl’ eagle is exactly equal to the number of its heads. These eagles can also enormously enlarge their IQ, when they form a group for a brainstorm. IQ of a group of Chernobyl’ eagles equals to the product of IQ’s of eagles in the group. So for example, the IQ of a group, consisting of two 4-headed eagles and one 7-headed is 4*4*7=112. The question is, how large can be an IQ of a group of eagles with a given total amount of heads.
Input
There is one positive integer N in the input, N ≤ 3000 — the total number of heads of Chernobyl’ eagles in a group.
Output
Your program should output a single number — a maximal IQ, which could have a group of Chernobyl’ eagles, with the total amount of heads equal to N.
Sample
input | output |
---|---|
5 |
6 |
Problem Author: folklore, proposed by Leonid Volkov
Problem Source: The Seventh Ural State University collegiate programming contest
Problem Source: The Seventh Ural State University collegiate programming contest
Tags: none
Difficulty: 141
题意:和为n,拆成若干个数,使得乘积最大
分析:显然,先拆成尽量多的3,在拆成2,这样乘积最大,因为肯定不能拆成1,然后之后所有数都可以用2,3构成,根据归纳法可以证明。
注意,4要拆成两个2
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <deque> 6 #include <vector> 7 #include <queue> 8 #include <iostream> 9 #include <algorithm> 10 #include <map> 11 #include <set> 12 #include <ctime> 13 using namespace std; 14 typedef long long LL; 15 typedef double DB; 16 #define For(i, s, t) for(int i = (s); i <= (t); i++) 17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--) 18 #define Rep(i, t) for(int i = (0); i < (t); i++) 19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--) 20 #define rep(i, x, t) for(int i = (x); i < (t); i++) 21 #define MIT (2147483647) 22 #define INF (1000000001) 23 #define MLL (1000000000000000001LL) 24 #define sz(x) ((int) (x).size()) 25 #define clr(x, y) memset(x, y, sizeof(x)) 26 #define puf push_front 27 #define pub push_back 28 #define pof pop_front 29 #define pob pop_back 30 #define ft first 31 #define sd second 32 #define mk make_pair 33 inline void SetIO(string Name) { 34 string Input = Name+".in", 35 Output = Name+".out"; 36 freopen(Input.c_str(), "r", stdin), 37 freopen(Output.c_str(), "w", stdout); 38 } 39 40 inline int Getint() { 41 int Ret = 0; 42 char Ch = ' '; 43 while(!(Ch >= '0' && Ch <= '9')) Ch = getchar(); 44 while(Ch >= '0' && Ch <= '9') { 45 Ret = Ret*10+Ch-'0'; 46 Ch = getchar(); 47 } 48 return Ret; 49 } 50 51 const int N = 1010, Mod = 10000; 52 int Arr[N], Len; 53 int n; 54 55 inline void Input() { 56 scanf("%d", &n); 57 } 58 59 inline void Mul(int x) { 60 For(i, 1, Len) Arr[i] *= x; 61 For(i, 1, Len) { 62 Arr[i+1] += Arr[i]/Mod; 63 Arr[i] %= Mod; 64 } 65 while(Arr[Len+1]) { 66 Len++; 67 Arr[Len+1] += Arr[Len]/Mod; 68 Arr[Len] %= Mod; 69 } 70 } 71 72 inline void Solve() { 73 Arr[1] = 1, Len = 1; 74 while(n > 4) Mul(3), n -= 3; 75 if(n == 4) Mul(2), n -= 2; 76 if(n == 3) Mul(3), n -= 3; 77 if(n == 2) Mul(2), n -= 2; 78 79 printf("%d", Arr[Len]); 80 Ford(i, Len-1, 1) printf("%04d", Arr[i]); 81 puts(""); 82 } 83 84 int main() { 85 #ifndef ONLINE_JUDGE 86 SetIO("F"); 87 #endif 88 Input(); 89 Solve(); 90 return 0; 91 }