Apple NetEase 2017 Test engineer Programming problem

Source: Internet
Author: User

Topic:

N Cows sitting in a row, each cow has an AI-only Apple, now you want to transfer apples between them, so that the last of all cows have the same number of apples, every time you can only take from one cow exactly two apples to the other cow, ask how many times you need to move can be graded, if the scheme does not exist, Output-1.

Input Description:

Each input contains a test case, the first line of each test case contains an integer n (1<=n<=100), and the next line consists of n integer ai (1<=ai<=100).

Output Description:

The output line indicates how many times you need to move the apples evenly, and output-1 if the scheme does not exist.

Output Example:

4

7 15 9 5

Output Example:

3

1#include <iostream>2#include <vector>3#include <algorithm>4 using namespacestd;5 6 intSumConstvector<int> &v)7 {8vector<int>::size_type n=v.size ();9     intsum=0;Ten      for(intI=0; i<n;i++) Onesum+=V[i]; A     returnsum; - } -  the intCountConstvector<int> &v,Const intN) - { -     if(SUM (v)%N) -         return-1; +     Else -     { +         intAve=sum (v)/N; A         intCnt=0; at          for(intI=0; i<n;i++) -         { -             if(ABS (V[i]-ave)%2) -                 return-1; -             Else -             { inCnt=cnt+abs (V[i]-ave)/2; -             } to         } +         returncnt/2; -     } the } *  $ intMain ()Panax Notoginseng { -     intN//N is the number of cows thevector<int>v; +Cin>>N; A      for(intI=0; i<n;i++) the     { +         inttemp; -Cin>>temp; $ V.push_back (temp); $     } -cout<<count (v,n); -}

Apple NetEase 2017 Test engineer Programming problem

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.