Test instructions: A total of 5 mountains, known to the little girl in the N-Mountain picked up n basket mushrooms, if n less than 5 in other mountains to pick up any weight of mushrooms, give the weight of each basket of mushrooms, she will come back to meet the three witch to surrender three of the weight of the mushroom and just 1024 multiples, otherwise she took the mushrooms, Then there will be a magician, as long as the little girl left the number of mushrooms more than 1024 she stole 1024, until not more than 1024, ask the little girl can bring back how many mushrooms.
Solution: When n is less than or equal to 3, as long as the half of the mushroom weight and give the sum of 1024 times times to the witch, with the remaining half of the 1024 multiples let the Magician steal, you can get the maximum value of 1024, When n equals 4, the two cases are discussed: 1.4 baskets can be used to make up 1024 multiples of the witch, then with not given and the remaining basket of 1024 multiples, you can get the maximum value of 1024. 2. If you can not get out of the only use not give out, so in those 4 to pick two are stolen after the biggest left. When n equals 5 o'clock, see if you can use 3 to make up 1024 times times, can choose the remaining two and steal the maximum can not be 0. "The staff was very helpful.
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;int main () {int n; while (~SCANF ("%d", &n)) {if (n <= 3) {while (n--) {int A; scanf ("%d", &a); } puts ("1024"); } else if (n = = 4) {int a[4]; for (int i = 0; i < 4; i++) scanf ("%d", &a[i]); int MAXN = 0; for (int i = 0, i < 4; i++) for (int j = i + 1, J < 4; J + +) for (int k = j + 1; k < ; 4; k++) if ((A[i] + a[j] + a[k])% 1024x768 = = 0) MAXN = 1024; if (MAXN= = 0) for (int i = 0, i < 4; i++) for (int j = i + 1; j < 4; J + +) MAXN = Max (MAXN, (A[i] + a[j]-1)% 1024 + 1); printf ("%d\n", MAXN); } else {int a[5]; int sum = 0; for (int i = 0; i < 5; i++) {scanf ("%d", &a[i]); Sum + = A[i]; } int maxn = 0; for (int i = 0, i < 5; i++) for (int j = i + 1, J < 5; J + +) for (int k = j + 1; k < ; 5; k++) {if ((A[i] + a[j] + a[k])% 1024x768 = = 0) MAXN = ma X (MAXN, (Sum-a[i]-a[j]-a[k]-1)% 1024 + 1); } printf ("%d\n", MAXN); }} return 0;}
HDU 4422 the Little Girl who picks mushrooms