HDU 4422 the Little Girl who picks mushrooms

Source: Internet
Author: User

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 &lt ; 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 &lt ; 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

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.