Huawei Oj_1988_ Array can be divided into two groups, so that the elements of the two groups combined and equal

Source: Internet
Author: User

Describe:

Write a function, pass in an int array, returns whether the array can be divided into two groups, so that the elements of the two groups are combined and equal, and that all multiples of 5 must be in one group, all multiples of 3 in another group (excluding a multiple of 5), which satisfies the above conditions and returns true , false when not satisfied.

Knowledge Points: Language basics, strings, loops, functions, pointers, enumerations, bitwise operations, structs, consortia, file operations, recursion
Topic Source: Internal finishing
Practice phase: Primary
Run time limit: 10Sec
Memory Limit: 128MByte
Input:

Enter the number of data entered

Enter an array of int


Output:

Returns TRUE or False


Sample input:
4
1
5
-5
1

                   
Sample output:
True

   


It's a little complicated, but I'll give you a way to experiment.
1: The entire array is first evaluated, if it is not an even number, it is returned directly to false, if it is the average, int tmpavege
2: To find all the numbers divisible by 5, to form a new array a5[], if it cannot be divisible by 5 but can be divisible by 3 to form a new array a3[ ], the remainder of the number, a[], adds the number of a5[] arrays, returns false if it is greater than the average Tmpavege, adds the number of a3[arrays, and returns false directly if it is greater than the average tmpavege;
3: With Tmpavege minus the a5[] array and getting int a5temp, the numbers in the a[array are grouped together, true if the sum can appear a5temp, or False if it returns.
 
You should be able to do this three-step implementation.
Feeling this problem is like packing problem.
1, to determine whether a multiple of 2, is not the case, directly return false. The results are SUM/2 into TMP
2, 5 multiples, 3 multiples in two arrays, two arrays and SUM5 sum3 respectively,  then compared to TMP, if one of them is greater than TMP, returns false, if equal, returns True, is less than the next step.
3, packing problem. A separate Mount tmp-sum3  returns True if it can be loaded, otherwise false ...


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.